diff options
-rw-r--r-- | chrome/browser/services/gcm/push_messaging_browsertest.cc | 2 | ||||
-rw-r--r-- | chrome/browser/services/gcm/push_messaging_service_impl.cc | 58 | ||||
-rw-r--r-- | content/child/runtime_features.cc | 3 | ||||
-rw-r--r-- | content/public/common/content_switches.cc | 3 | ||||
-rw-r--r-- | content/public/common/content_switches.h | 1 |
5 files changed, 44 insertions, 23 deletions
diff --git a/chrome/browser/services/gcm/push_messaging_browsertest.cc b/chrome/browser/services/gcm/push_messaging_browsertest.cc index 859f05c..5b20c30 100644 --- a/chrome/browser/services/gcm/push_messaging_browsertest.cc +++ b/chrome/browser/services/gcm/push_messaging_browsertest.cc @@ -116,6 +116,8 @@ class PushMessagingBrowserTest : public InProcessBrowserTest { void SetUpCommandLine(base::CommandLine* command_line) override { command_line->AppendSwitch( switches::kEnableExperimentalWebPlatformFeatures); + command_line->AppendSwitch( + switches::kEnablePushMessagePayload); InProcessBrowserTest::SetUpCommandLine(command_line); } diff --git a/chrome/browser/services/gcm/push_messaging_service_impl.cc b/chrome/browser/services/gcm/push_messaging_service_impl.cc index 401bdde..6a59cbe 100644 --- a/chrome/browser/services/gcm/push_messaging_service_impl.cc +++ b/chrome/browser/services/gcm/push_messaging_service_impl.cc @@ -31,6 +31,7 @@ #include "content/public/browser/render_frame_host.h" #include "content/public/browser/web_contents.h" #include "content/public/common/child_process_host.h" +#include "content/public/common/content_switches.h" #include "content/public/common/platform_notification_data.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/base/l10n/l10n_util.h" @@ -148,9 +149,10 @@ void PushMessagingServiceImpl::OnMessage( const GCMClient::IncomingMessage& message) { // The Push API only exposes a single string of data in the push event fired // on the Service Worker. When developers send messages using GCM to the Push - // API, they must pass a single key-value pair, where the key is "data" and - // the value is the string they want to be passed to their Service Worker. - // For example, they could send the following JSON using the HTTPS GCM API: + // API and want to include a message payload, they must pass a single key- + // value pair, where the key is "data" and the value is the string they want + // to be passed to their Service Worker. For example, they could send the + // following JSON using the HTTPS GCM API: // { // "registration_ids": ["FOO", "BAR"], // "data": { @@ -161,30 +163,40 @@ void PushMessagingServiceImpl::OnMessage( // TODO(johnme): Make sure this is clearly documented for developers. PushMessagingApplicationId application_id = PushMessagingApplicationId::Parse(app_id); - GCMClient::MessageData::const_iterator it = message.data.find("data"); - if (application_id.IsValid() && it != message.data.end()) { - if (!HasPermission(application_id.origin)) { - // The |origin| lost push permission. We need to unregister and drop this - // message. - Unregister(application_id, UnregisterCallback()); - return; - } - const std::string& data = it->second; - content::BrowserContext::DeliverPushMessage( - profile_, - application_id.origin, - application_id.service_worker_registration_id, - data, - base::Bind(&PushMessagingServiceImpl::DeliverMessageCallback, - weak_factory_.GetWeakPtr(), - application_id, - message)); - } else { - // Drop the message, as it is invalid. + // Drop messages whose application is is invalid. + if (!application_id.IsValid()) { DeliverMessageCallback(application_id, message, content::PUSH_DELIVERY_STATUS_INVALID_MESSAGE); + return; + } + + // |origin| may have lost push permission. Unregister and drop this message. + if (!HasPermission(application_id.origin)) { + Unregister(application_id, UnregisterCallback()); + return; + } + + std::string data; + + // TODO(peter): Message payloads are disabled pending mandatory encryption. + // https://crbug.com/449184 + if (base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnablePushMessagePayload)) { + GCMClient::MessageData::const_iterator it = message.data.find("data"); + if (it != message.data.end()) + data = it->second; } + + content::BrowserContext::DeliverPushMessage( + profile_, + application_id.origin, + application_id.service_worker_registration_id, + data, + base::Bind(&PushMessagingServiceImpl::DeliverMessageCallback, + weak_factory_.GetWeakPtr(), + application_id, + message)); } void PushMessagingServiceImpl::SetProfileForTesting(Profile* profile) { diff --git a/content/child/runtime_features.cc b/content/child/runtime_features.cc index baf7019..79b0f24 100644 --- a/content/child/runtime_features.cc +++ b/content/child/runtime_features.cc @@ -179,6 +179,9 @@ void SetRuntimeFeaturesDefaultsAndUpdateFromArgs( if (command_line.HasSwitch(switches::kReducedReferrerGranularity)) WebRuntimeFeatures::enableReducedReferrerGranularity(true); + if (command_line.HasSwitch(switches::kEnablePushMessagePayload)) + WebRuntimeFeatures::enablePushMessagingData(true); + if (command_line.HasSwitch(switches::kDisableV8IdleTasks)) WebRuntimeFeatures::enableV8IdleTasks(false); else diff --git a/content/public/common/content_switches.cc b/content/public/common/content_switches.cc index 9a41cc6..5ecc7a8 100644 --- a/content/public/common/content_switches.cc +++ b/content/public/common/content_switches.cc @@ -366,6 +366,9 @@ const char kEnablePinch[] = "enable-pinch"; // also applys to workers. const char kEnablePreciseMemoryInfo[] = "enable-precise-memory-info"; +// Enables payloads for received push messages when using the W3C Push API. +const char kEnablePushMessagePayload[] = "enable-push-message-payload"; + // Set options to cache V8 data. (off, preparse data, or code) const char kV8CacheOptions[] = "v8-cache-options"; diff --git a/content/public/common/content_switches.h b/content/public/common/content_switches.h index 5cd17459..90e6f14 100644 --- a/content/public/common/content_switches.h +++ b/content/public/common/content_switches.h @@ -112,6 +112,7 @@ CONTENT_EXPORT extern const char kEnableOneCopy[]; CONTENT_EXPORT extern const char kEnableOverlayFullscreenVideo[]; CONTENT_EXPORT extern const char kEnablePinch[]; CONTENT_EXPORT extern const char kEnablePreciseMemoryInfo[]; +CONTENT_EXPORT extern const char kEnablePushMessagePayload[]; CONTENT_EXPORT extern const char kEnableRegionBasedColumns[]; CONTENT_EXPORT extern const char kEnableRendererMojoChannel[]; CONTENT_EXPORT extern const char kEnableSandboxLogging[]; |