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

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

Issue 134393003: app_shell: Convert ExtensionsWebContentsObserver to BrowserContext from Profile (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/extensions/extension_web_contents_observer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/extensions/extension_web_contents_observer.h" 5 #include "chrome/browser/extensions/extension_web_contents_observer.h"
6 6
7 #include "chrome/browser/extensions/api/messaging/message_service.h" 7 #include "chrome/browser/extensions/api/messaging/message_service.h"
8 #include "chrome/browser/extensions/extension_service.h" 8 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/extensions/extension_system.h" 9 #include "chrome/browser/extensions/extension_system.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/common/extensions/api/messaging/message.h" 10 #include "chrome/common/extensions/api/messaging/message.h"
12 #include "chrome/common/extensions/extension_messages.h" 11 #include "chrome/common/extensions/extension_messages.h"
13 #include "chrome/common/url_constants.h" 12 #include "chrome/common/url_constants.h"
14 #include "content/public/browser/child_process_security_policy.h" 13 #include "content/public/browser/child_process_security_policy.h"
15 #include "content/public/browser/render_process_host.h" 14 #include "content/public/browser/render_process_host.h"
16 #include "content/public/browser/render_view_host.h" 15 #include "content/public/browser/render_view_host.h"
17 #include "content/public/browser/site_instance.h" 16 #include "content/public/browser/site_instance.h"
18 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
19 #include "extensions/browser/extension_registry.h" 18 #include "extensions/browser/extension_registry.h"
20 #include "extensions/browser/view_type_utils.h" 19 #include "extensions/browser/view_type_utils.h"
21 #include "extensions/common/constants.h" 20 #include "extensions/common/constants.h"
22 21
23 DEFINE_WEB_CONTENTS_USER_DATA_KEY(extensions::ExtensionWebContentsObserver); 22 DEFINE_WEB_CONTENTS_USER_DATA_KEY(extensions::ExtensionWebContentsObserver);
24 23
25 namespace extensions { 24 namespace extensions {
26 25
27 ExtensionWebContentsObserver::ExtensionWebContentsObserver( 26 ExtensionWebContentsObserver::ExtensionWebContentsObserver(
28 content::WebContents* web_contents) 27 content::WebContents* web_contents)
29 : content::WebContentsObserver(web_contents), 28 : content::WebContentsObserver(web_contents),
30 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())) { 29 browser_context_(web_contents->GetBrowserContext()) {
31 } 30 }
32 31
33 ExtensionWebContentsObserver::~ExtensionWebContentsObserver() { 32 ExtensionWebContentsObserver::~ExtensionWebContentsObserver() {
34 } 33 }
35 34
36 void ExtensionWebContentsObserver::RenderViewCreated( 35 void ExtensionWebContentsObserver::RenderViewCreated(
37 content::RenderViewHost* render_view_host) { 36 content::RenderViewHost* render_view_host) {
38 render_view_host->Send(new ExtensionMsg_NotifyRenderViewType( 37 render_view_host->Send(new ExtensionMsg_NotifyRenderViewType(
39 render_view_host->GetRoutingID(), 38 render_view_host->GetRoutingID(),
40 extensions::GetViewType(web_contents()))); 39 extensions::GetViewType(web_contents())));
(...skipping 12 matching lines...) Expand all
53 type == Manifest::TYPE_LEGACY_PACKAGED_APP || 52 type == Manifest::TYPE_LEGACY_PACKAGED_APP ||
54 (type == Manifest::TYPE_PLATFORM_APP && 53 (type == Manifest::TYPE_PLATFORM_APP &&
55 extension->location() == Manifest::COMPONENT)) { 54 extension->location() == Manifest::COMPONENT)) {
56 content::ChildProcessSecurityPolicy::GetInstance()->GrantScheme( 55 content::ChildProcessSecurityPolicy::GetInstance()->GrantScheme(
57 process->GetID(), chrome::kChromeUIScheme); 56 process->GetID(), chrome::kChromeUIScheme);
58 } 57 }
59 58
60 // Some extensions use file:// URLs. 59 // Some extensions use file:// URLs.
61 if (type == Manifest::TYPE_EXTENSION || 60 if (type == Manifest::TYPE_EXTENSION ||
62 type == Manifest::TYPE_LEGACY_PACKAGED_APP) { 61 type == Manifest::TYPE_LEGACY_PACKAGED_APP) {
63 if (ExtensionPrefs::Get(profile_)->AllowFileAccess(extension->id())) { 62 ExtensionPrefs* prefs = ExtensionPrefs::Get(browser_context_);
63 if (prefs->AllowFileAccess(extension->id())) {
64 content::ChildProcessSecurityPolicy::GetInstance()->GrantScheme( 64 content::ChildProcessSecurityPolicy::GetInstance()->GrantScheme(
65 process->GetID(), content::kFileScheme); 65 process->GetID(), content::kFileScheme);
66 } 66 }
67 } 67 }
68 68
69 switch (type) { 69 switch (type) {
70 case Manifest::TYPE_EXTENSION: 70 case Manifest::TYPE_EXTENSION:
71 case Manifest::TYPE_USER_SCRIPT: 71 case Manifest::TYPE_USER_SCRIPT:
72 case Manifest::TYPE_HOSTED_APP: 72 case Manifest::TYPE_HOSTED_APP:
73 case Manifest::TYPE_LEGACY_PACKAGED_APP: 73 case Manifest::TYPE_LEGACY_PACKAGED_APP:
(...skipping 21 matching lines...) Expand all
95 bool handled = true; 95 bool handled = true;
96 IPC_BEGIN_MESSAGE_MAP(ExtensionWebContentsObserver, message) 96 IPC_BEGIN_MESSAGE_MAP(ExtensionWebContentsObserver, message)
97 IPC_MESSAGE_HANDLER(ExtensionHostMsg_PostMessage, OnPostMessage) 97 IPC_MESSAGE_HANDLER(ExtensionHostMsg_PostMessage, OnPostMessage)
98 IPC_MESSAGE_UNHANDLED(handled = false) 98 IPC_MESSAGE_UNHANDLED(handled = false)
99 IPC_END_MESSAGE_MAP() 99 IPC_END_MESSAGE_MAP()
100 return handled; 100 return handled;
101 } 101 }
102 102
103 void ExtensionWebContentsObserver::OnPostMessage(int port_id, 103 void ExtensionWebContentsObserver::OnPostMessage(int port_id,
104 const Message& message) { 104 const Message& message) {
105 MessageService* message_service = MessageService::Get(profile_); 105 MessageService* message_service = MessageService::Get(browser_context_);
106 if (message_service) { 106 if (message_service) {
107 message_service->PostMessage(port_id, message); 107 message_service->PostMessage(port_id, message);
108 } 108 }
109 } 109 }
110 110
111 const Extension* ExtensionWebContentsObserver::GetExtension( 111 const Extension* ExtensionWebContentsObserver::GetExtension(
112 content::RenderViewHost* render_view_host) { 112 content::RenderViewHost* render_view_host) {
113 // Note that due to ChromeContentBrowserClient::GetEffectiveURL(), hosted apps 113 // Note that due to ChromeContentBrowserClient::GetEffectiveURL(), hosted apps
114 // (excluding bookmark apps) will have a chrome-extension:// URL for their 114 // (excluding bookmark apps) will have a chrome-extension:// URL for their
115 // site, so we can ignore that wrinkle here. 115 // site, so we can ignore that wrinkle here.
116 content::SiteInstance* site_instance = render_view_host->GetSiteInstance(); 116 content::SiteInstance* site_instance = render_view_host->GetSiteInstance();
117 const GURL& site = site_instance->GetSiteURL(); 117 const GURL& site = site_instance->GetSiteURL();
118 118
119 if (!site.SchemeIs(kExtensionScheme)) 119 if (!site.SchemeIs(kExtensionScheme))
120 return NULL; 120 return NULL;
121 121
122 ExtensionService* service = 122 std::string extension_id = site.host();
123 ExtensionSystem::Get(profile_)->extension_service(); 123 ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context_);
124 if (!service)
125 return NULL;
126 124
127 // Reload the extension if it has crashed. 125 // Reload the extension if it has crashed.
128 // TODO(yoz): This reload doesn't happen synchronously for unpacked 126 // TODO(yoz): This reload doesn't happen synchronously for unpacked
129 // extensions. It seems to be fast enough, but there is a race. 127 // extensions. It seems to be fast enough, but there is a race.
130 // We should delay loading until the extension has reloaded. 128 // We should delay loading until the extension has reloaded.
131 if (service->GetTerminatedExtension(site.host())) 129 if (registry->GetExtensionById(extension_id, ExtensionRegistry::TERMINATED)) {
132 service->ReloadExtension(site.host()); 130 ExtensionSystem::GetForBrowserContext(browser_context_)->
131 extension_service()->ReloadExtension(extension_id);
132 }
133 133
134 // May be null if the extension doesn't exist, for example if somebody typos 134 // May be null if the extension doesn't exist, for example if somebody typos
135 // a chrome-extension:// URL. 135 // a chrome-extension:// URL.
136 return ExtensionRegistry::Get(profile_)->enabled_extensions().GetByID( 136 return registry->enabled_extensions().GetByID(extension_id);
137 site.host());
138 } 137 }
139 138
140 } // namespace extensions 139 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_web_contents_observer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698