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

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

Issue 9737001: Fix crash in AppNotifyChannelSetup when incognito profiles are used. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_tab_helper.h" 5 #include "chrome/browser/extensions/extension_tab_helper.h"
6 6
7 #include "chrome/browser/extensions/extension_service.h" 7 #include "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/extensions/webstore_inline_installer.h" 8 #include "chrome/browser/extensions/webstore_inline_installer.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/sessions/restore_tab_helper.h" 10 #include "chrome/browser/sessions/restore_tab_helper.h"
11 #include "chrome/browser/ui/browser.h" 11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_list.h" 12 #include "chrome/browser/ui/browser_list.h"
13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
14 #include "chrome/common/chrome_notification_types.h" 14 #include "chrome/common/chrome_notification_types.h"
15 #include "chrome/common/extensions/extension_action.h" 15 #include "chrome/common/extensions/extension_action.h"
16 #include "chrome/common/extensions/extension_icon_set.h" 16 #include "chrome/common/extensions/extension_icon_set.h"
17 #include "chrome/common/extensions/extension_messages.h" 17 #include "chrome/common/extensions/extension_messages.h"
18 #include "chrome/common/extensions/extension_resource.h" 18 #include "chrome/common/extensions/extension_resource.h"
19 #include "content/public/browser/invalidate_type.h" 19 #include "content/public/browser/invalidate_type.h"
20 #include "content/public/browser/navigation_details.h" 20 #include "content/public/browser/navigation_details.h"
21 #include "content/public/browser/notification_service.h" 21 #include "content/public/browser/notification_service.h"
22 #include "content/public/browser/render_process_host.h" 22 #include "content/public/browser/render_process_host.h"
23 #include "content/public/browser/render_view_host.h" 23 #include "content/public/browser/render_view_host.h"
24 #include "content/public/browser/render_widget_host_view.h" 24 #include "content/public/browser/render_widget_host_view.h"
25 #include "content/public/browser/web_contents.h" 25 #include "content/public/browser/web_contents.h"
26 #include "ui/gfx/image/image.h" 26 #include "ui/gfx/image/image.h"
27 27
28 using content::WebContents; 28 using content::WebContents;
29 29
30 namespace {
31
32 const char kPermissionError[] = "permission_error";
33 const char kIncognitoError[] =
jstritar 2012/03/22 20:21:10 Not sure where I should extract the two copies of
asargent_no_longer_on_chrome 2012/03/22 20:58:11 Sure, putting it in extension_constants.h seems fi
jstritar 2012/03/23 15:31:43 Done.
34 "This API is not accessible by 'split' mode "
35 "extensions in incognito windows.";
36
37 } // namespace
38
30 ExtensionTabHelper::ExtensionTabHelper(TabContentsWrapper* wrapper) 39 ExtensionTabHelper::ExtensionTabHelper(TabContentsWrapper* wrapper)
31 : content::WebContentsObserver(wrapper->web_contents()), 40 : content::WebContentsObserver(wrapper->web_contents()),
32 delegate_(NULL), 41 delegate_(NULL),
33 extension_app_(NULL), 42 extension_app_(NULL),
34 ALLOW_THIS_IN_INITIALIZER_LIST( 43 ALLOW_THIS_IN_INITIALIZER_LIST(
35 extension_function_dispatcher_(wrapper->profile(), this)), 44 extension_function_dispatcher_(wrapper->profile(), this)),
36 wrapper_(wrapper) { 45 wrapper_(wrapper) {
37 } 46 }
38 47
39 ExtensionTabHelper::~ExtensionTabHelper() { 48 ExtensionTabHelper::~ExtensionTabHelper() {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 181
173 // Check for permission first. 182 // Check for permission first.
174 Profile* profile = 183 Profile* profile =
175 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 184 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
176 ExtensionService* extension_service = profile->GetExtensionService(); 185 ExtensionService* extension_service = profile->GetExtensionService();
177 extensions::ProcessMap* process_map = extension_service->process_map(); 186 extensions::ProcessMap* process_map = extension_service->process_map();
178 content::RenderProcessHost* process = 187 content::RenderProcessHost* process =
179 tab_contents_wrapper()->web_contents()->GetRenderProcessHost(); 188 tab_contents_wrapper()->web_contents()->GetRenderProcessHost();
180 const Extension* extension = 189 const Extension* extension =
181 extension_service->GetInstalledApp(requestor_url); 190 extension_service->GetInstalledApp(requestor_url);
182 bool allowed = 191
183 extension && 192 std::string error;
184 extension->HasAPIPermission( 193 if (!extension ||
185 ExtensionAPIPermission::kAppNotifications) && 194 !extension->HasAPIPermission(
186 process_map->Contains(extension->id(), process->GetID()); 195 ExtensionAPIPermission::kAppNotifications) ||
187 if (!allowed) { 196 !process_map->Contains(extension->id(), process->GetID()))
197 error = kPermissionError;
198
199 // Make sure the extension can cross to the main profile, if called from an
200 // an incognito window.
201 if (profile->IsOffTheRecord() &&
202 !extension_service->CanCrossIncognito(extension))
203 error = kIncognitoError;
204
205 if (!error.empty()) {
188 Send(new ExtensionMsg_GetAppNotifyChannelResponse( 206 Send(new ExtensionMsg_GetAppNotifyChannelResponse(
189 return_route_id, "", "permission_error", callback_id)); 207 return_route_id, "", error, callback_id));
190 return; 208 return;
191 } 209 }
192 210
193 AppNotifyChannelUI* ui = new AppNotifyChannelUIImpl( 211 AppNotifyChannelUI* ui = new AppNotifyChannelUIImpl(
194 GetBrowser(), tab_contents_wrapper(), extension->name()); 212 GetBrowser(), tab_contents_wrapper(), extension->name());
195 213
196 scoped_refptr<AppNotifyChannelSetup> channel_setup( 214 scoped_refptr<AppNotifyChannelSetup> channel_setup(
197 new AppNotifyChannelSetup(profile, 215 new AppNotifyChannelSetup(profile,
198 extension->id(), 216 extension->id(),
199 client_id, 217 client_id,
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 void ExtensionTabHelper::OnInlineInstallFailure(int install_id, 317 void ExtensionTabHelper::OnInlineInstallFailure(int install_id,
300 int return_route_id, 318 int return_route_id,
301 const std::string& error) { 319 const std::string& error) {
302 Send(new ExtensionMsg_InlineWebstoreInstallResponse( 320 Send(new ExtensionMsg_InlineWebstoreInstallResponse(
303 return_route_id, install_id, false, error)); 321 return_route_id, install_id, false, error));
304 } 322 }
305 323
306 WebContents* ExtensionTabHelper::GetAssociatedWebContents() const { 324 WebContents* ExtensionTabHelper::GetAssociatedWebContents() const {
307 return web_contents(); 325 return web_contents();
308 } 326 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_local_filesystem_apitest.cc ('k') | chrome/browser/extensions/extension_tabs_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698