Enable Shadow DOM and scoped stylesheet for extensions.

BUG=127985
TEST=manual


Review URL: https://chromiumcodereview.appspot.com/10332169

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@142323 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/renderer/chrome_render_view_observer.cc b/chrome/renderer/chrome_render_view_observer.cc
index 03658b5..f54caa27 100644
--- a/chrome/renderer/chrome_render_view_observer.cc
+++ b/chrome/renderer/chrome_render_view_observer.cc
@@ -58,6 +58,7 @@
 using WebKit::WebAccessibilityObject;
 using WebKit::WebCString;
 using WebKit::WebDataSource;
+using WebKit::WebDocument;
 using WebKit::WebFrame;
 using WebKit::WebIconURL;
 using WebKit::WebRect;
@@ -482,6 +483,32 @@
   return allowed;
 }
 
+bool ChromeRenderViewObserver::IsExperimentalWebFeatureAllowed(
+    const WebDocument& document) {
+  // Experimental Web API is enabled when
+  // - The specific API is allowed from command line flag, or
+  // - If the document is running extensions or apps which
+  //   has the "experimental" permission, or
+  // - The document is running Web UI.
+  WebSecurityOrigin origin = document.securityOrigin();
+  if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme))
+    return true;
+  const extensions::Extension* extension =
+      extension_dispatcher_->extensions()->GetExtensionOrAppByURL(
+          ExtensionURLInfo(origin, document.url()));
+  if (!extension)
+    return false;
+  return (extension_dispatcher_->IsExtensionActive(extension->id()) &&
+          extension->HasAPIPermission(ExtensionAPIPermission::kExperimental));
+}
+
+bool ChromeRenderViewObserver::allowWebComponents(const WebDocument& document,
+                                                  bool defaultValue) {
+  if (defaultValue)
+    return true;
+  return IsExperimentalWebFeatureAllowed(document);
+}
+
 static void SendInsecureContentSignal(int signal) {
   UMA_HISTOGRAM_ENUMERATION("SSL.InsecureContent", signal,
                             INSECURE_CONTENT_NUM_EVENTS);
diff --git a/chrome/renderer/chrome_render_view_observer.h b/chrome/renderer/chrome_render_view_observer.h
index 923e0067..9ba86ca 100644
--- a/chrome/renderer/chrome_render_view_observer.h
+++ b/chrome/renderer/chrome_render_view_observer.h
@@ -104,6 +104,7 @@
                                       bool default_value) OVERRIDE;
   virtual bool allowWriteToClipboard(WebKit::WebFrame* frame,
                                      bool default_value) OVERRIDE;
+  virtual bool allowWebComponents(const WebKit::WebDocument&, bool) OVERRIDE;
   virtual void didNotAllowPlugins(WebKit::WebFrame* frame) OVERRIDE;
   virtual void didNotAllowScript(WebKit::WebFrame* frame) OVERRIDE;
   virtual bool allowDisplayingInsecureContent(
@@ -182,6 +183,9 @@
   // Determines if a host is in the strict security host set.
   bool IsStrictSecurityHost(const std::string& host);
 
+  // Determines if the document has a permission to use experimental Web API
+  bool IsExperimentalWebFeatureAllowed(const WebKit::WebDocument& document);
+
   // Save the JavaScript to preload if a ViewMsg_WebUIJavaScript is received.
   scoped_ptr<WebUIJavaScript> webui_javascript_;