Index: chrome/renderer/extensions/extension_dispatcher.cc |
diff --git a/chrome/renderer/extensions/extension_dispatcher.cc b/chrome/renderer/extensions/extension_dispatcher.cc |
index 9ed183928dfd4d046998e2a11da09f4c1641016d..dba51592f3bf78068cb2406596a642d896590dbb 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 { |
@@ -40,6 +42,8 @@ using WebKit::WebDataSource; |
using WebKit::WebFrame; |
using WebKit::WebSecurityPolicy; |
using WebKit::WebString; |
+using WebKit::WebVector; |
+using WebKit::WebView; |
using content::RenderThread; |
ExtensionDispatcher::ExtensionDispatcher() |
@@ -178,17 +182,44 @@ 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> temp_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()) { |
+ temp_patterns.push_back( |
+ WebString::fromUTF8(extension->url().spec() + "*")); |
+ } |
} |
- extensions_.Insert(extension); |
+ if (!temp_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: consider enhancing WebView to allow removing single stylesheets, |
Aaron Boodman
2011/11/14 22:48:07
The convention is TODO(<whoever knows the most abo
miket_OOO
2011/11/14 23:48:51
Done.
|
+ // or else to edit the pattern set associated with one. |
+ WebVector<WebString> patterns; |
+ patterns.assign(temp_patterns); |
+ WebView::addUserStyleSheet( |
+ WebString::fromUTF8(ResourceBundle::GetSharedInstance(). |
+ GetRawDataResource(IDR_PLATFORM_APP_CSS)), |
+ patterns, |
+ WebView::UserContentInjectInAllFrames, |
+ WebView::UserStyleInjectInExistingDocuments); |
+ } |
} |
void ExtensionDispatcher::OnUnloaded(const std::string& id) { |
@@ -197,6 +228,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( |