summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authormiket@chromium.org <miket@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-15 02:17:53 +0000
committermiket@chromium.org <miket@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-15 02:17:53 +0000
commit9776e82e6f0c0b011007b12dc5e14b31e30da62b (patch)
treef43f2a119f2d3fcb14fe5b890440900b375123a7 /chrome
parent4e86b6e1e67ef8cb2ff2770dfe4b7c87d09d85d8 (diff)
downloadchromium_src-9776e82e6f0c0b011007b12dc5e14b31e30da62b.zip
chromium_src-9776e82e6f0c0b011007b12dc5e14b31e30da62b.tar.gz
chromium_src-9776e82e6f0c0b011007b12dc5e14b31e30da62b.tar.bz2
Insert default stylesheet for platform apps.
Review URL: http://codereview.chromium.org/8542001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110017 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/chrome_content_browser_client.cc1
-rw-r--r--chrome/browser/extensions/extension_service.cc10
-rw-r--r--chrome/common/extensions/extension_messages.cc13
-rw-r--r--chrome/common/extensions/extension_messages.h6
-rw-r--r--chrome/renderer/extensions/extension_dispatcher.cc54
-rw-r--r--chrome/renderer/extensions/extension_dispatcher.h3
-rw-r--r--chrome/renderer/renderer_resources.grd1
-rw-r--r--chrome/renderer/resources/extensions/platform_app.css12
8 files changed, 78 insertions, 22 deletions
diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc
index f8398cb..3853866 100644
--- a/chrome/browser/chrome_content_browser_client.cc
+++ b/chrome/browser/chrome_content_browser_client.cc
@@ -573,6 +573,7 @@ void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
switches::kEnableIPCFuzzing,
switches::kEnableLazyBackgroundPages,
switches::kEnableNaCl,
+ switches::kEnablePlatformApps,
switches::kEnablePrintPreview,
switches::kEnableSearchProviderApiV2,
switches::kEnableWatchdog,
diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc
index b9d848a..3f77711 100644
--- a/chrome/browser/extensions/extension_service.cc
+++ b/chrome/browser/extensions/extension_service.cc
@@ -922,8 +922,10 @@ void ExtensionService::NotifyExtensionLoaded(const Extension* extension) {
Profile* host_profile =
Profile::FromBrowserContext(host->browser_context());
if (host_profile->GetOriginalProfile() == profile_->GetOriginalProfile()) {
+ std::vector<ExtensionMsg_Loaded_Params> loaded_extensions(
+ 1, ExtensionMsg_Loaded_Params(extension));
host->Send(
- new ExtensionMsg_Loaded(ExtensionMsg_Loaded_Params(extension)));
+ new ExtensionMsg_Loaded(loaded_extensions));
}
}
@@ -2332,10 +2334,12 @@ void ExtensionService::Observe(int type,
*Extension::GetScriptingWhitelist()));
// Loaded extensions.
+ std::vector<ExtensionMsg_Loaded_Params> loaded_extensions;
for (size_t i = 0; i < extensions_.size(); ++i) {
- process->Send(new ExtensionMsg_Loaded(
- ExtensionMsg_Loaded_Params(extensions_[i])));
+ loaded_extensions.push_back(
+ ExtensionMsg_Loaded_Params(extensions_[i]));
}
+ process->Send(new ExtensionMsg_Loaded(loaded_extensions));
break;
}
case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: {
diff --git a/chrome/common/extensions/extension_messages.cc b/chrome/common/extensions/extension_messages.cc
index 7ebee77..a326289 100644
--- a/chrome/common/extensions/extension_messages.cc
+++ b/chrome/common/extensions/extension_messages.cc
@@ -15,7 +15,7 @@ ExtensionMsg_Loaded_Params::~ExtensionMsg_Loaded_Params() {}
ExtensionMsg_Loaded_Params::ExtensionMsg_Loaded_Params(
const ExtensionMsg_Loaded_Params& other)
- : manifest(other.manifest->DeepCopy()),
+ : manifest(other.manifest),
location(other.location),
path(other.path),
apis(other.apis),
@@ -37,15 +37,16 @@ ExtensionMsg_Loaded_Params::ExtensionMsg_Loaded_Params(
// As we need more bits of extension data in the renderer, add more keys to
// this list.
const char* kRendererExtensionKeys[] = {
- extension_manifest_keys::kPublicKey,
- extension_manifest_keys::kName,
- extension_manifest_keys::kVersion,
+ extension_manifest_keys::kApp,
+ extension_manifest_keys::kContentScripts,
extension_manifest_keys::kIcons,
+ extension_manifest_keys::kName,
extension_manifest_keys::kPageAction,
extension_manifest_keys::kPageActions,
extension_manifest_keys::kPermissions,
- extension_manifest_keys::kApp,
- extension_manifest_keys::kContentScripts
+ extension_manifest_keys::kPlatformApp,
+ extension_manifest_keys::kPublicKey,
+ extension_manifest_keys::kVersion,
};
// Copy only the data we need.
diff --git a/chrome/common/extensions/extension_messages.h b/chrome/common/extensions/extension_messages.h
index 2973259..2ca8c28 100644
--- a/chrome/common/extensions/extension_messages.h
+++ b/chrome/common/extensions/extension_messages.h
@@ -107,7 +107,7 @@ struct ExtensionMsg_Loaded_Params {
scoped_refptr<Extension> ConvertToExtension() const;
// The subset of the extension manifest data we send to renderers.
- scoped_ptr<DictionaryValue> manifest;
+ linked_ptr<DictionaryValue> manifest;
// The location the extension was installed from.
Extension::Location location;
@@ -202,9 +202,9 @@ IPC_MESSAGE_CONTROL1(ExtensionMsg_ActivateExtension,
IPC_MESSAGE_CONTROL1(ExtensionMsg_ActivateApplication,
std::string /* extension_id */)
-// Notifies the renderer that an extension was loaded in the browser.
+// Notifies the renderer that extensions were loaded in the browser.
IPC_MESSAGE_CONTROL1(ExtensionMsg_Loaded,
- ExtensionMsg_Loaded_Params)
+ std::vector<ExtensionMsg_Loaded_Params>)
// Notifies the renderer that an extension was unloaded in the browser.
IPC_MESSAGE_CONTROL1(ExtensionMsg_Unloaded,
diff --git a/chrome/renderer/extensions/extension_dispatcher.cc b/chrome/renderer/extensions/extension_dispatcher.cc
index 32d6731..e3e0060 100644
--- a/chrome/renderer/extensions/extension_dispatcher.cc
+++ b/chrome/renderer/extensions/extension_dispatcher.cc
@@ -29,6 +29,8 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
+#include "ui/base/resource/resource_bundle.h"
#include "v8/include/v8.h"
namespace {
@@ -42,6 +44,8 @@ using WebKit::WebDataSource;
using WebKit::WebFrame;
using WebKit::WebSecurityPolicy;
using WebKit::WebString;
+using WebKit::WebVector;
+using WebKit::WebView;
using content::RenderThread;
ExtensionDispatcher::ExtensionDispatcher()
@@ -180,17 +184,45 @@ void ExtensionDispatcher::OnDeliverMessage(int target_port_id,
NULL); // All render views.
}
-void ExtensionDispatcher::OnLoaded(const ExtensionMsg_Loaded_Params& params) {
- scoped_refptr<const Extension> extension(params.ConvertToExtension());
- if (!extension) {
- // This can happen if extension parsing fails for any reason. One reason
- // this can legitimately happen is if the
- // --enable-experimental-extension-apis changes at runtime, which happens
- // during browser tests. Existing renderers won't know about the change.
- return;
+void ExtensionDispatcher::OnLoaded(
+ const std::vector<ExtensionMsg_Loaded_Params>& loaded_extensions) {
+ std::vector<WebString> platform_app_patterns;
+
+ std::vector<ExtensionMsg_Loaded_Params>::const_iterator i;
+ for (i = loaded_extensions.begin(); i != loaded_extensions.end(); ++i) {
+ scoped_refptr<const Extension> extension(i->ConvertToExtension());
+ if (!extension) {
+ // This can happen if extension parsing fails for any reason. One reason
+ // this can legitimately happen is if the
+ // --enable-experimental-extension-apis changes at runtime, which happens
+ // during browser tests. Existing renderers won't know about the change.
+ continue;
+ }
+
+ extensions_.Insert(extension);
+
+ if (extension->is_platform_app()) {
+ platform_app_patterns.push_back(
+ WebString::fromUTF8(extension->url().spec() + "*"));
+ }
}
- extensions_.Insert(extension);
+ if (!platform_app_patterns.empty()) {
+ // We have collected a set of platform-app extensions, so let's tell WebKit
+ // about them so that it can provide a default stylesheet for them.
+ //
+ // TODO(miket): consider enhancing WebView to allow removing
+ // single stylesheets, or else to edit the pattern set associated
+ // with one.
+ WebVector<WebString> patterns;
+ patterns.assign(platform_app_patterns);
+ WebView::addUserStyleSheet(
+ WebString::fromUTF8(ResourceBundle::GetSharedInstance().
+ GetRawDataResource(IDR_PLATFORM_APP_CSS)),
+ patterns,
+ WebView::UserContentInjectInAllFrames,
+ WebView::UserStyleInjectInExistingDocuments);
+ }
}
void ExtensionDispatcher::OnUnloaded(const std::string& id) {
@@ -199,6 +231,10 @@ void ExtensionDispatcher::OnUnloaded(const std::string& id) {
// we'd like it to get a new isolated world ID, so that it can pick up the
// changed origin whitelist.
user_script_slave_->RemoveIsolatedWorld(id);
+
+ // We don't do anything with existing platform-app stylesheets. They will
+ // stay resident, but the URL pattern corresponding to the unloaded
+ // extension's URL just won't match anything anymore.
}
void ExtensionDispatcher::OnSetScriptingWhitelist(
diff --git a/chrome/renderer/extensions/extension_dispatcher.h b/chrome/renderer/extensions/extension_dispatcher.h
index 6f32898..f20e44a 100644
--- a/chrome/renderer/extensions/extension_dispatcher.h
+++ b/chrome/renderer/extensions/extension_dispatcher.h
@@ -98,7 +98,8 @@ class ExtensionDispatcher : public content::RenderProcessObserver {
const GURL& event_url);
void OnDeliverMessage(int target_port_id, const std::string& message);
void OnSetFunctionNames(const std::vector<std::string>& names);
- void OnLoaded(const ExtensionMsg_Loaded_Params& params);
+ void OnLoaded(
+ const std::vector<ExtensionMsg_Loaded_Params>& loaded_extensions);
void OnUnloaded(const std::string& id);
void OnSetScriptingWhitelist(
const Extension::ScriptingWhitelist& extension_ids);
diff --git a/chrome/renderer/renderer_resources.grd b/chrome/renderer/renderer_resources.grd
index 9ec8c0b..d241093 100644
--- a/chrome/renderer/renderer_resources.grd
+++ b/chrome/renderer/renderer_resources.grd
@@ -26,6 +26,7 @@ without changes to the corresponding grd file. fb9 -->
<include name="IDR_NET_ERROR_HTML" file="resources\neterror.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_SAD_PLUGIN" file="resources\sadplugin.png" type="BINDATA" />
<include name="IDR_ERROR_APP_HTML" file="resources\error_app.html" flattenhtml="true" type="BINDATA" />
+ <include name="IDR_PLATFORM_APP_CSS" file="resources\extensions\platform_app.css" type="BINDATA" />
</includes>
</release>
</grit>
diff --git a/chrome/renderer/resources/extensions/platform_app.css b/chrome/renderer/resources/extensions/platform_app.css
new file mode 100644
index 0000000..fddbe16
--- /dev/null
+++ b/chrome/renderer/resources/extensions/platform_app.css
@@ -0,0 +1,12 @@
+/*
+ * A style sheet for Chrome platform apps.
+ */
+
+@namespace "http://www.w3.org/1999/xhtml";
+
+html {
+ background-color: #cccccf;
+ color: #333;
+ -webkit-user-select: none;
+ cursor: default;
+}