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

Side by Side Diff: extensions/browser/extension_web_contents_observer.cc

Issue 1142993002: Don't send unnecessary ExtensionMsg_Loaded IPCs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: commnets Created 5 years, 6 months 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "extensions/browser/extension_web_contents_observer.h" 5 #include "extensions/browser/extension_web_contents_observer.h"
6 6
7 #include "content/public/browser/child_process_security_policy.h" 7 #include "content/public/browser/child_process_security_policy.h"
8 #include "content/public/browser/render_frame_host.h" 8 #include "content/public/browser/render_frame_host.h"
9 #include "content/public/browser/render_process_host.h" 9 #include "content/public/browser/render_process_host.h"
10 #include "content/public/browser/render_view_host.h" 10 #include "content/public/browser/render_view_host.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 // Some extensions use file:// URLs. 83 // Some extensions use file:// URLs.
84 if (type == Manifest::TYPE_EXTENSION || 84 if (type == Manifest::TYPE_EXTENSION ||
85 type == Manifest::TYPE_LEGACY_PACKAGED_APP) { 85 type == Manifest::TYPE_LEGACY_PACKAGED_APP) {
86 ExtensionPrefs* prefs = ExtensionPrefs::Get(browser_context_); 86 ExtensionPrefs* prefs = ExtensionPrefs::Get(browser_context_);
87 if (prefs->AllowFileAccess(extension->id())) { 87 if (prefs->AllowFileAccess(extension->id())) {
88 content::ChildProcessSecurityPolicy::GetInstance()->GrantScheme( 88 content::ChildProcessSecurityPolicy::GetInstance()->GrantScheme(
89 process->GetID(), url::kFileScheme); 89 process->GetID(), url::kFileScheme);
90 } 90 }
91 } 91 }
92 92
93 switch (type) { 93 // Tells the new view that it's hosted in an extension process.
94 case Manifest::TYPE_EXTENSION: 94 //
95 case Manifest::TYPE_USER_SCRIPT: 95 // This will often be a rendant IPC, because activating extensions happens at
96 case Manifest::TYPE_HOSTED_APP: 96 // the process level, not at the view level. However, without some mild
97 case Manifest::TYPE_LEGACY_PACKAGED_APP: 97 // refactoring this isn't trivial to do, and this way is simpler.
98 case Manifest::TYPE_PLATFORM_APP: 98 //
99 // Always send a Loaded message before ActivateExtension so that 99 // Plus, we can delete the concept of activating an extension once site
100 // ExtensionDispatcher knows what Extension is active, not just its ID. 100 // isolation is turned on.
101 // This is important for classifying the Extension's JavaScript context 101 render_view_host->Send(new ExtensionMsg_ActivateExtension(extension->id()));
102 // correctly (see ExtensionDispatcher::ClassifyJavaScriptContext).
103 // We also have to include the tab-specific permissions here, since it's
104 // an extension process.
105 render_view_host->Send(
106 new ExtensionMsg_Loaded(std::vector<ExtensionMsg_Loaded_Params>(
107 1, ExtensionMsg_Loaded_Params(
108 extension, true /* include tab permissions */))));
109 render_view_host->Send(
110 new ExtensionMsg_ActivateExtension(extension->id()));
111 break;
112
113 case Manifest::TYPE_UNKNOWN:
114 case Manifest::TYPE_THEME:
115 case Manifest::TYPE_SHARED_MODULE:
116 break;
117
118 case Manifest::NUM_LOAD_TYPES:
119 NOTREACHED();
120 }
121 } 102 }
122 103
123 void ExtensionWebContentsObserver::RenderFrameCreated( 104 void ExtensionWebContentsObserver::RenderFrameCreated(
124 content::RenderFrameHost* render_frame_host) { 105 content::RenderFrameHost* render_frame_host) {
125 const Extension* extension = GetExtensionForRenderFrame(render_frame_host); 106 const Extension* extension = GetExtensionForRenderFrame(render_frame_host);
126 if (extension) { 107 if (extension) {
127 ExtensionsBrowserClient::Get()->RegisterMojoServices(render_frame_host, 108 ExtensionsBrowserClient::Get()->RegisterMojoServices(render_frame_host,
128 extension); 109 extension);
129 } 110 }
130 } 111 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 // site, so we can ignore that wrinkle here. 174 // site, so we can ignore that wrinkle here.
194 const GURL& site = render_view_host->GetSiteInstance()->GetSiteURL(); 175 const GURL& site = render_view_host->GetSiteInstance()->GetSiteURL();
195 176
196 if (!site.SchemeIs(kExtensionScheme)) 177 if (!site.SchemeIs(kExtensionScheme))
197 return std::string(); 178 return std::string();
198 179
199 return site.host(); 180 return site.host();
200 } 181 }
201 182
202 } // namespace extensions 183 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698