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

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

Issue 11365181: Remove GetExtensionService from Profile. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: replace missing extension_system include Created 8 years 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 (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/navigation_observer.h" 5 #include "chrome/browser/extensions/navigation_observer.h"
6 6
7 #include "chrome/browser/extensions/extension_install_ui.h" 7 #include "chrome/browser/extensions/extension_install_ui.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/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
10 #include "content/public/browser/navigation_controller.h" 11 #include "content/public/browser/navigation_controller.h"
11 #include "content/public/browser/navigation_entry.h" 12 #include "content/public/browser/navigation_entry.h"
12 #include "content/public/browser/notification_service.h" 13 #include "content/public/browser/notification_service.h"
13 #include "content/public/browser/notification_types.h" 14 #include "content/public/browser/notification_types.h"
14 15
15 using content::NavigationController; 16 using content::NavigationController;
16 using content::NavigationEntry; 17 using content::NavigationEntry;
17 18
18 namespace extensions { 19 namespace extensions {
(...skipping 29 matching lines...) Expand all
48 void NavigationObserver::PromptToEnableExtensionIfNecessary( 49 void NavigationObserver::PromptToEnableExtensionIfNecessary(
49 NavigationController* nav_controller) { 50 NavigationController* nav_controller) {
50 // Bail out if we're already running a prompt. 51 // Bail out if we're already running a prompt.
51 if (!in_progress_prompt_extension_id_.empty()) 52 if (!in_progress_prompt_extension_id_.empty())
52 return; 53 return;
53 54
54 NavigationEntry* nav_entry = nav_controller->GetActiveEntry(); 55 NavigationEntry* nav_entry = nav_controller->GetActiveEntry();
55 if (!nav_entry) 56 if (!nav_entry)
56 return; 57 return;
57 58
58 ExtensionService* extension_service = profile_->GetExtensionService(); 59 ExtensionService* extension_service =
60 extensions::ExtensionSystem::Get(profile_)->extension_service();
59 const Extension* extension = extension_service->disabled_extensions()-> 61 const Extension* extension = extension_service->disabled_extensions()->
60 GetExtensionOrAppByURL(ExtensionURLInfo(nav_entry->GetURL())); 62 GetExtensionOrAppByURL(ExtensionURLInfo(nav_entry->GetURL()));
61 if (!extension) 63 if (!extension)
62 return; 64 return;
63 65
64 // Try not to repeatedly prompt the user about the same extension. 66 // Try not to repeatedly prompt the user about the same extension.
65 if (prompted_extensions_.find(extension->id()) != prompted_extensions_.end()) 67 if (prompted_extensions_.find(extension->id()) != prompted_extensions_.end())
66 return; 68 return;
67 prompted_extensions_.insert(extension->id()); 69 prompted_extensions_.insert(extension->id());
68 70
69 ExtensionPrefs* extension_prefs = extension_service->extension_prefs(); 71 ExtensionPrefs* extension_prefs = extension_service->extension_prefs();
70 if (extension_prefs->DidExtensionEscalatePermissions(extension->id())) { 72 if (extension_prefs->DidExtensionEscalatePermissions(extension->id())) {
71 // Keep track of the extension id and nav controller we're prompting for. 73 // Keep track of the extension id and nav controller we're prompting for.
72 // These must be reset in InstallUIProceed and InstallUIAbort. 74 // These must be reset in InstallUIProceed and InstallUIAbort.
73 in_progress_prompt_extension_id_ = extension->id(); 75 in_progress_prompt_extension_id_ = extension->id();
74 in_progress_prompt_navigation_controller_ = nav_controller; 76 in_progress_prompt_navigation_controller_ = nav_controller;
75 77
76 extension_install_prompt_.reset( 78 extension_install_prompt_.reset(
77 new ExtensionInstallPrompt(nav_controller->GetWebContents())); 79 new ExtensionInstallPrompt(nav_controller->GetWebContents()));
78 extension_install_prompt_->ConfirmReEnable(this, extension); 80 extension_install_prompt_->ConfirmReEnable(this, extension);
79 } 81 }
80 } 82 }
81 83
82 void NavigationObserver::InstallUIProceed() { 84 void NavigationObserver::InstallUIProceed() {
83 ExtensionService* extension_service = profile_->GetExtensionService(); 85 ExtensionService* extension_service =
86 extensions::ExtensionSystem::Get(profile_)->extension_service();
84 const Extension* extension = extension_service->GetExtensionById( 87 const Extension* extension = extension_service->GetExtensionById(
85 in_progress_prompt_extension_id_, true); 88 in_progress_prompt_extension_id_, true);
86 NavigationController* nav_controller = 89 NavigationController* nav_controller =
87 in_progress_prompt_navigation_controller_; 90 in_progress_prompt_navigation_controller_;
88 CHECK(extension); 91 CHECK(extension);
89 CHECK(nav_controller); 92 CHECK(nav_controller);
90 93
91 in_progress_prompt_extension_id_ = ""; 94 in_progress_prompt_extension_id_ = "";
92 in_progress_prompt_navigation_controller_ = NULL; 95 in_progress_prompt_navigation_controller_ = NULL;
93 bool record_oauth2_grant = extension_install_prompt_->record_oauth2_grant(); 96 bool record_oauth2_grant = extension_install_prompt_->record_oauth2_grant();
94 extension_install_prompt_.reset(); 97 extension_install_prompt_.reset();
95 98
96 // Grant permissions, re-enable the extension, and then reload the tab. 99 // Grant permissions, re-enable the extension, and then reload the tab.
97 extension_service->GrantPermissionsAndEnableExtension( 100 extension_service->GrantPermissionsAndEnableExtension(
98 extension, record_oauth2_grant); 101 extension, record_oauth2_grant);
99 nav_controller->Reload(true); 102 nav_controller->Reload(true);
100 } 103 }
101 104
102 void NavigationObserver::InstallUIAbort(bool user_initiated) { 105 void NavigationObserver::InstallUIAbort(bool user_initiated) {
103 ExtensionService* extension_service = profile_->GetExtensionService(); 106 ExtensionService* extension_service =
107 extensions::ExtensionSystem::Get(profile_)->extension_service();
104 const Extension* extension = extension_service->GetExtensionById( 108 const Extension* extension = extension_service->GetExtensionById(
105 in_progress_prompt_extension_id_, true); 109 in_progress_prompt_extension_id_, true);
106 110
107 in_progress_prompt_extension_id_ = ""; 111 in_progress_prompt_extension_id_ = "";
108 in_progress_prompt_navigation_controller_ = NULL; 112 in_progress_prompt_navigation_controller_ = NULL;
109 extension_install_prompt_.reset(); 113 extension_install_prompt_.reset();
110 114
111 std::string histogram_name = user_initiated ? 115 std::string histogram_name = user_initiated ?
112 "Extensions.Permissions_ReEnableCancel" : 116 "Extensions.Permissions_ReEnableCancel" :
113 "Extensions.Permissions_ReEnableAbort"; 117 "Extensions.Permissions_ReEnableAbort";
114 ExtensionService::RecordPermissionMessagesHistogram( 118 ExtensionService::RecordPermissionMessagesHistogram(
115 extension, histogram_name.c_str()); 119 extension, histogram_name.c_str());
116 } 120 }
117 121
118 } // namespace extensions 122 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_toolbar_model_browsertest.cc ('k') | chrome/browser/extensions/options_page_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698