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

Side by Side Diff: chrome/browser/ui/browser.cc

Issue 562533002: Remove deprecated extension notification from Browser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Modified the comments Created 6 years, 3 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
« chrome/browser/ui/browser.h ('K') | « chrome/browser/ui/browser.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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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/ui/browser.h" 5 #include "chrome/browser/ui/browser.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 #endif // defined(OS_WIN) 10 #endif // defined(OS_WIN)
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 #include "content/public/browser/render_view_host.h" 174 #include "content/public/browser/render_view_host.h"
175 #include "content/public/browser/render_widget_host_view.h" 175 #include "content/public/browser/render_widget_host_view.h"
176 #include "content/public/browser/site_instance.h" 176 #include "content/public/browser/site_instance.h"
177 #include "content/public/browser/user_metrics.h" 177 #include "content/public/browser/user_metrics.h"
178 #include "content/public/browser/web_contents.h" 178 #include "content/public/browser/web_contents.h"
179 #include "content/public/common/content_switches.h" 179 #include "content/public/common/content_switches.h"
180 #include "content/public/common/page_zoom.h" 180 #include "content/public/common/page_zoom.h"
181 #include "content/public/common/renderer_preferences.h" 181 #include "content/public/common/renderer_preferences.h"
182 #include "content/public/common/webplugininfo.h" 182 #include "content/public/common/webplugininfo.h"
183 #include "extensions/browser/extension_prefs.h" 183 #include "extensions/browser/extension_prefs.h"
184 #include "extensions/browser/extension_registry.h"
184 #include "extensions/browser/extension_system.h" 185 #include "extensions/browser/extension_system.h"
185 #include "extensions/common/constants.h" 186 #include "extensions/common/constants.h"
186 #include "extensions/common/extension.h" 187 #include "extensions/common/extension.h"
187 #include "extensions/common/manifest_handlers/background_info.h" 188 #include "extensions/common/manifest_handlers/background_info.h"
188 #include "net/base/filename_util.h" 189 #include "net/base/filename_util.h"
189 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 190 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
190 #include "net/cookies/cookie_monster.h" 191 #include "net/cookies/cookie_monster.h"
191 #include "net/url_request/url_request_context.h" 192 #include "net/url_request/url_request_context.h"
192 #include "third_party/WebKit/public/web/WebWindowFeatures.h" 193 #include "third_party/WebKit/public/web/WebWindowFeatures.h"
193 #include "ui/base/l10n/l10n_util.h" 194 #include "ui/base/l10n/l10n_util.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 private: 322 private:
322 Browser* browser_; 323 Browser* browser_;
323 324
324 DISALLOW_COPY_AND_ASSIGN(InterstitialObserver); 325 DISALLOW_COPY_AND_ASSIGN(InterstitialObserver);
325 }; 326 };
326 327
327 /////////////////////////////////////////////////////////////////////////////// 328 ///////////////////////////////////////////////////////////////////////////////
328 // Browser, Constructors, Creation, Showing: 329 // Browser, Constructors, Creation, Showing:
329 330
330 Browser::Browser(const CreateParams& params) 331 Browser::Browser(const CreateParams& params)
331 : type_(params.type), 332 : extension_registry_observer_(this),
333 type_(params.type),
332 profile_(params.profile), 334 profile_(params.profile),
333 window_(NULL), 335 window_(NULL),
334 tab_strip_model_delegate_(new chrome::BrowserTabStripModelDelegate(this)), 336 tab_strip_model_delegate_(new chrome::BrowserTabStripModelDelegate(this)),
335 tab_strip_model_(new TabStripModel(tab_strip_model_delegate_.get(), 337 tab_strip_model_(
336 params.profile)), 338 new TabStripModel(tab_strip_model_delegate_.get(), params.profile)),
337 app_name_(params.app_name), 339 app_name_(params.app_name),
338 is_trusted_source_(params.trusted_source), 340 is_trusted_source_(params.trusted_source),
339 cancel_download_confirmation_state_(NOT_PROMPTED), 341 cancel_download_confirmation_state_(NOT_PROMPTED),
340 override_bounds_(params.initial_bounds), 342 override_bounds_(params.initial_bounds),
341 initial_show_state_(params.initial_show_state), 343 initial_show_state_(params.initial_show_state),
342 is_session_restore_(params.is_session_restore), 344 is_session_restore_(params.is_session_restore),
343 host_desktop_type_(BrowserWindow::AdjustHostDesktopType( 345 host_desktop_type_(
344 params.host_desktop_type)), 346 BrowserWindow::AdjustHostDesktopType(params.host_desktop_type)),
345 content_setting_bubble_model_delegate_( 347 content_setting_bubble_model_delegate_(
346 new BrowserContentSettingBubbleModelDelegate(this)), 348 new BrowserContentSettingBubbleModelDelegate(this)),
347 toolbar_model_delegate_(new BrowserToolbarModelDelegate(this)), 349 toolbar_model_delegate_(new BrowserToolbarModelDelegate(this)),
348 tab_restore_service_delegate_(new BrowserTabRestoreServiceDelegate(this)), 350 tab_restore_service_delegate_(new BrowserTabRestoreServiceDelegate(this)),
349 synced_window_delegate_(new BrowserSyncedWindowDelegate(this)), 351 synced_window_delegate_(new BrowserSyncedWindowDelegate(this)),
350 bookmark_bar_state_(BookmarkBar::HIDDEN), 352 bookmark_bar_state_(BookmarkBar::HIDDEN),
351 command_controller_(new chrome::BrowserCommandController(this)), 353 command_controller_(new chrome::BrowserCommandController(this)),
352 window_has_shown_(false), 354 window_has_shown_(false),
353 chrome_updater_factory_(this), 355 chrome_updater_factory_(this),
354 weak_factory_(this), 356 weak_factory_(this),
(...skipping 13 matching lines...) Expand all
368 unload_controller_.reset(new chrome::UnloadController(this)); 370 unload_controller_.reset(new chrome::UnloadController(this));
369 371
370 if (!app_name_.empty()) 372 if (!app_name_.empty())
371 chrome::RegisterAppPrefs(app_name_, profile_); 373 chrome::RegisterAppPrefs(app_name_, profile_);
372 tab_strip_model_->AddObserver(this); 374 tab_strip_model_->AddObserver(this);
373 375
374 toolbar_model_.reset(new ToolbarModelImpl(toolbar_model_delegate_.get())); 376 toolbar_model_.reset(new ToolbarModelImpl(toolbar_model_delegate_.get()));
375 search_model_.reset(new SearchModel()); 377 search_model_.reset(new SearchModel());
376 search_delegate_.reset(new SearchDelegate(search_model_.get())); 378 search_delegate_.reset(new SearchDelegate(search_model_.get()));
377 379
378 registrar_.Add(this, 380 extension_registry_observer_.Add(
379 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, 381 extensions::ExtensionRegistry::Get(profile_));
380 content::Source<Profile>(profile_->GetOriginalProfile())); 382
381 registrar_.Add(this,
382 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
383 content::Source<Profile>(profile_->GetOriginalProfile()));
384 registrar_.Add(this,
385 extensions::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED,
386 content::Source<Profile>(profile_->GetOriginalProfile()));
387 registrar_.Add(this, 383 registrar_.Add(this,
388 extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, 384 extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
389 content::NotificationService::AllSources()); 385 content::NotificationService::AllSources());
386
390 #if defined(ENABLE_THEMES) 387 #if defined(ENABLE_THEMES)
391 registrar_.Add( 388 registrar_.Add(
392 this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, 389 this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
393 content::Source<ThemeService>( 390 content::Source<ThemeService>(
394 ThemeServiceFactory::GetForProfile(profile_))); 391 ThemeServiceFactory::GetForProfile(profile_)));
395 #endif 392 #endif
396 registrar_.Add(this, chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, 393 registrar_.Add(this, chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED,
397 content::NotificationService::AllSources()); 394 content::NotificationService::AllSources());
398 395
399 profile_pref_registrar_.Init(profile_->GetPrefs()); 396 profile_pref_registrar_.Init(profile_->GetPrefs());
(...skipping 1498 matching lines...) Expand 10 before | Expand all | Expand 10 after
1898 if (data.web_contents == tab_strip_model_->GetActiveWebContents()) { 1895 if (data.web_contents == tab_strip_model_->GetActiveWebContents()) {
1899 // Only show the zoom bubble for zoom changes in the active window. 1896 // Only show the zoom bubble for zoom changes in the active window.
1900 window_->ZoomChangedForActiveTab(data.can_show_bubble && 1897 window_->ZoomChangedForActiveTab(data.can_show_bubble &&
1901 window_->IsActive()); 1898 window_->IsActive());
1902 // Change the zoom commands state based on the zoom state 1899 // Change the zoom commands state based on the zoom state
1903 command_controller_->ZoomStateChanged(); 1900 command_controller_->ZoomStateChanged();
1904 } 1901 }
1905 } 1902 }
1906 1903
1907 /////////////////////////////////////////////////////////////////////////////// 1904 ///////////////////////////////////////////////////////////////////////////////
1908 // Browser, ui::SelectFileDialog::Listener implementation: 1905 // Browser, ui::SelectFileDialog::Listener implementation:
Peter Kasting 2014/09/10 18:40:20 Nit: I'm not a fan of these big dividers between s
Jitu( very slow this week) 2014/09/11 06:08:16 Dear Peter, I have not touched this function. So a
Bernhard Bauer 2014/09/11 08:09:20 IIUC, Peter's comment is not about the function, b
1909 1906
1910 void Browser::FileSelected(const base::FilePath& path, int index, 1907 void Browser::FileSelected(const base::FilePath& path, int index,
1911 void* params) { 1908 void* params) {
1912 FileSelectedWithExtraInfo(ui::SelectedFileInfo(path, path), index, params); 1909 FileSelectedWithExtraInfo(ui::SelectedFileInfo(path, path), index, params);
1913 } 1910 }
1914 1911
1915 void Browser::FileSelectedWithExtraInfo(const ui::SelectedFileInfo& file_info, 1912 void Browser::FileSelectedWithExtraInfo(const ui::SelectedFileInfo& file_info,
1916 int index, 1913 int index,
1917 void* params) { 1914 void* params) {
1918 profile_->set_last_selected_directory(file_info.file_path.DirName()); 1915 profile_->set_last_selected_directory(file_info.file_path.DirName());
1919 1916
1920 GURL url = net::FilePathToFileURL(file_info.local_path); 1917 GURL url = net::FilePathToFileURL(file_info.local_path);
1921 1918
1922 #if defined(OS_CHROMEOS) 1919 #if defined(OS_CHROMEOS)
1923 drive::util::MaybeSetDriveURL(profile_, file_info.file_path, &url); 1920 drive::util::MaybeSetDriveURL(profile_, file_info.file_path, &url);
1924 #endif 1921 #endif
1925 1922
1926 if (url.is_empty()) 1923 if (url.is_empty())
1927 return; 1924 return;
1928 1925
1929 OpenURL(OpenURLParams( 1926 OpenURL(OpenURLParams(
1930 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); 1927 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false));
1931 } 1928 }
1932 1929
1930 // Called when an extension is uninstalled
Peter Kasting 2014/09/10 18:40:20 Nit: Don't add comments like this. If they're imp
Jitu( very slow this week) 2014/09/11 06:08:16 Done.
1931 void Browser::OnExtensionUninstalled(content::BrowserContext* browser_context,
1932 const extensions::Extension* extension,
1933 extensions::UninstallReason reason) {
1934 if (window() && window()->GetLocationBar())
1935 window()->GetLocationBar()->UpdatePageActions();
1936 }
1937
1938 // Called when an extension is loaded
1939 void Browser::OnExtensionLoaded(content::BrowserContext* browser_context,
1940 const extensions::Extension* extension) {
1941 chrome::UpdateCommandEnabled(
1942 this,
1943 IDC_BOOKMARK_PAGE,
1944 !chrome::ShouldRemoveBookmarkThisPageUI(profile_));
1945 chrome::UpdateCommandEnabled(
1946 this,
1947 IDC_BOOKMARK_ALL_TABS,
1948 !chrome::ShouldRemoveBookmarkOpenPagesUI(profile_));
1949 }
1950
1951 // Called when an extension is unloaded
1952 void Browser::OnExtensionUnloaded(
1953 content::BrowserContext* browser_context,
1954 const extensions::Extension* extension,
1955 extensions::UnloadedExtensionInfo::Reason reason) {
1956 chrome::UpdateCommandEnabled(
1957 this,
1958 IDC_BOOKMARK_PAGE,
1959 !chrome::ShouldRemoveBookmarkThisPageUI(profile_));
1960 chrome::UpdateCommandEnabled(
1961 this,
1962 IDC_BOOKMARK_ALL_TABS,
1963 !chrome::ShouldRemoveBookmarkOpenPagesUI(profile_));
1964
1965 if (window()->GetLocationBar())
1966 window()->GetLocationBar()->UpdatePageActions();
1967
1968 // Close any tabs from the unloaded extension, unless it's terminated,
1969 // in which case let the sad tabs remain.
1970 if (reason != extensions::UnloadedExtensionInfo::REASON_TERMINATE) {
1971 // Iterate backwards as we may remove items while iterating.
1972 for (int i = tab_strip_model_->count() - 1; i >= 0; --i) {
1973 WebContents* web_contents = tab_strip_model_->GetWebContentsAt(i);
1974 // Two cases are handled here:
1975 // - The scheme check is for when an extension page is loaded in a
1976 // tab, e.g. chrome-extension://id/page.html.
1977 // - The extension_app check is for apps, which can have non-extension
1978 // schemes, e.g. https://mail.google.com if you have the Gmail app
1979 // installed.
1980 if ((web_contents->GetURL().SchemeIs(extensions::kExtensionScheme) &&
1981 web_contents->GetURL().host() == extension->id()) ||
1982 (extensions::TabHelper::FromWebContents(web_contents)
1983 ->extension_app() == extension)) {
1984 tab_strip_model_->CloseWebContentsAt(i, TabStripModel::CLOSE_NONE);
1985 }
1986 }
1987 }
1988 }
1933 /////////////////////////////////////////////////////////////////////////////// 1989 ///////////////////////////////////////////////////////////////////////////////
1934 // Browser, content::NotificationObserver implementation: 1990 // Browser, content::NotificationObserver implementation:
1935 1991
1936 void Browser::Observe(int type, 1992 void Browser::Observe(int type,
1937 const content::NotificationSource& source, 1993 const content::NotificationSource& source,
1938 const content::NotificationDetails& details) { 1994 const content::NotificationDetails& details) {
1939 switch (type) { 1995 switch (type) {
1940 case extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: {
1941 chrome::UpdateCommandEnabled(
1942 this,
1943 IDC_BOOKMARK_PAGE,
1944 !chrome::ShouldRemoveBookmarkThisPageUI(profile_));
1945 chrome::UpdateCommandEnabled(
1946 this,
1947 IDC_BOOKMARK_ALL_TABS,
1948 !chrome::ShouldRemoveBookmarkOpenPagesUI(profile_));
1949
1950 if (window()->GetLocationBar())
1951 window()->GetLocationBar()->UpdatePageActions();
1952
1953 const extensions::UnloadedExtensionInfo* extension_info =
1954 content::Details<extensions::UnloadedExtensionInfo>(details).ptr();
1955
1956 // Close any tabs from the unloaded extension, unless it's terminated,
1957 // in which case let the sad tabs remain.
1958 if (extension_info->reason !=
1959 extensions::UnloadedExtensionInfo::REASON_TERMINATE) {
1960 const Extension* extension = extension_info->extension;
1961 // Iterate backwards as we may remove items while iterating.
1962 for (int i = tab_strip_model_->count() - 1; i >= 0; --i) {
1963 WebContents* web_contents = tab_strip_model_->GetWebContentsAt(i);
1964 // Two cases are handled here:
1965 // - The scheme check is for when an extension page is loaded in a
1966 // tab, e.g. chrome-extension://id/page.html.
1967 // - The extension_app check is for apps, which can have non-extension
1968 // schemes, e.g. https://mail.google.com if you have the Gmail app
1969 // installed.
1970 if ((web_contents->GetURL().SchemeIs(extensions::kExtensionScheme) &&
1971 web_contents->GetURL().host() == extension->id()) ||
1972 (extensions::TabHelper::FromWebContents(
1973 web_contents)->extension_app() == extension)) {
1974 tab_strip_model_->CloseWebContentsAt(i, TabStripModel::CLOSE_NONE);
1975 }
1976 }
1977 }
1978 break;
1979 }
1980
1981 case extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: { 1996 case extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: {
1982 Profile* profile = content::Source<Profile>(source).ptr(); 1997 Profile* profile = content::Source<Profile>(source).ptr();
1983 if (profile_->IsSameProfile(profile) && window()->GetLocationBar()) 1998 if (profile_->IsSameProfile(profile) && window()->GetLocationBar())
1984 window()->GetLocationBar()->InvalidatePageActions(); 1999 window()->GetLocationBar()->InvalidatePageActions();
1985 break; 2000 break;
1986 } 2001 }
1987 2002
1988 case extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED:
1989 chrome::UpdateCommandEnabled(
1990 this,
1991 IDC_BOOKMARK_PAGE,
1992 !chrome::ShouldRemoveBookmarkThisPageUI(profile_));
1993 chrome::UpdateCommandEnabled(
1994 this,
1995 IDC_BOOKMARK_ALL_TABS,
1996 !chrome::ShouldRemoveBookmarkOpenPagesUI(profile_));
1997 // fallthrough
1998 case extensions::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED:
1999 // During window creation on Windows we may end up calling into
2000 // SHAppBarMessage, which internally spawns a nested message loop. This
2001 // makes it possible for us to end up here before window creation has
2002 // completed, at which point window_ is NULL. See 94752 for details.
Peter Kasting 2014/09/10 18:40:20 Nit: Please copy this comment to your new code loc
Jitu( very slow this week) 2014/09/11 06:08:16 Done.
2003 if (window() && window()->GetLocationBar())
2004 window()->GetLocationBar()->UpdatePageActions();
2005 break;
2006
2007 #if defined(ENABLE_THEMES) 2003 #if defined(ENABLE_THEMES)
2008 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: 2004 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED:
2009 window()->UserChangedTheme(); 2005 window()->UserChangedTheme();
2010 break; 2006 break;
2011 #endif 2007 #endif
2012 2008
2013 case chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED: { 2009 case chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED: {
2014 WebContents* web_contents = content::Source<WebContents>(source).ptr(); 2010 WebContents* web_contents = content::Source<WebContents>(source).ptr();
2015 if (web_contents == tab_strip_model_->GetActiveWebContents()) { 2011 if (web_contents == tab_strip_model_->GetActiveWebContents()) {
2016 LocationBar* location_bar = window()->GetLocationBar(); 2012 LocationBar* location_bar = window()->GetLocationBar();
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
2472 if (contents && !allow_js_access) { 2468 if (contents && !allow_js_access) {
2473 contents->web_contents()->GetController().LoadURL( 2469 contents->web_contents()->GetController().LoadURL(
2474 target_url, 2470 target_url,
2475 content::Referrer(), 2471 content::Referrer(),
2476 content::PAGE_TRANSITION_LINK, 2472 content::PAGE_TRANSITION_LINK,
2477 std::string()); // No extra headers. 2473 std::string()); // No extra headers.
2478 } 2474 }
2479 2475
2480 return contents != NULL; 2476 return contents != NULL;
2481 } 2477 }
OLDNEW
« chrome/browser/ui/browser.h ('K') | « chrome/browser/ui/browser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698