Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Unified Diff: chrome/renderer/extensions/extension_dispatcher.cc

Issue 8542001: Insert default stylesheet for platform apps. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Simplified per mpcomplete, aa's comments. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..5e9b179f717e0c2d912b49977ac91be1b7ca3e21 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,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> temp_patterns;
Mihai Parparita -not on Chrome 2011/11/15 00:48:29 Nit: Can this be called platform_app_patterns or s
+
+ 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(miket): consider enhancing WebView to allow removing
+ // single stylesheets, 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 +229,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(

Powered by Google App Engine
This is Rietveld 408576698