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

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

Issue 301733006: Zoom Extension API (chrome) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments, make zoom bubble icon loading safer. Created 6 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 | Annotate | Revision Log
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" 43 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
44 #include "chrome/browser/custom_handlers/register_protocol_handler_infobar_deleg ate.h" 44 #include "chrome/browser/custom_handlers/register_protocol_handler_infobar_deleg ate.h"
45 #include "chrome/browser/custom_handlers/register_protocol_handler_permission_re quest.h" 45 #include "chrome/browser/custom_handlers/register_protocol_handler_permission_re quest.h"
46 #include "chrome/browser/defaults.h" 46 #include "chrome/browser/defaults.h"
47 #include "chrome/browser/devtools/devtools_toggle_action.h" 47 #include "chrome/browser/devtools/devtools_toggle_action.h"
48 #include "chrome/browser/devtools/devtools_window.h" 48 #include "chrome/browser/devtools/devtools_window.h"
49 #include "chrome/browser/download/download_item_model.h" 49 #include "chrome/browser/download/download_item_model.h"
50 #include "chrome/browser/download/download_service.h" 50 #include "chrome/browser/download/download_service.h"
51 #include "chrome/browser/download/download_service_factory.h" 51 #include "chrome/browser/download/download_service_factory.h"
52 #include "chrome/browser/download/download_shelf.h" 52 #include "chrome/browser/download/download_shelf.h"
53 #include "chrome/browser/extensions/api/tabs/tabs_event_router.h"
54 #include "chrome/browser/extensions/api/tabs/tabs_windows_api.h"
53 #include "chrome/browser/extensions/browser_extension_window_controller.h" 55 #include "chrome/browser/extensions/browser_extension_window_controller.h"
54 #include "chrome/browser/extensions/extension_service.h" 56 #include "chrome/browser/extensions/extension_service.h"
55 #include "chrome/browser/extensions/tab_helper.h" 57 #include "chrome/browser/extensions/tab_helper.h"
56 #include "chrome/browser/favicon/favicon_tab_helper.h" 58 #include "chrome/browser/favicon/favicon_tab_helper.h"
57 #include "chrome/browser/file_select_helper.h" 59 #include "chrome/browser/file_select_helper.h"
58 #include "chrome/browser/first_run/first_run.h" 60 #include "chrome/browser/first_run/first_run.h"
59 #include "chrome/browser/history/top_sites.h" 61 #include "chrome/browser/history/top_sites.h"
60 #include "chrome/browser/infobars/infobar_service.h" 62 #include "chrome/browser/infobars/infobar_service.h"
61 #include "chrome/browser/infobars/simple_alert_infobar_delegate.h" 63 #include "chrome/browser/infobars/simple_alert_infobar_delegate.h"
62 #include "chrome/browser/lifetime/application_lifetime.h" 64 #include "chrome/browser/lifetime/application_lifetime.h"
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 return OpenURLFromTab(NULL, params); 885 return OpenURLFromTab(NULL, params);
884 } 886 }
885 887
886 /////////////////////////////////////////////////////////////////////////////// 888 ///////////////////////////////////////////////////////////////////////////////
887 // Browser, TabStripModelObserver implementation: 889 // Browser, TabStripModelObserver implementation:
888 890
889 void Browser::TabInsertedAt(WebContents* contents, 891 void Browser::TabInsertedAt(WebContents* contents,
890 int index, 892 int index,
891 bool foreground) { 893 bool foreground) {
892 SetAsDelegate(contents, this); 894 SetAsDelegate(contents, this);
895 SetAsObserver(contents);
893 SessionTabHelper* session_tab_helper = 896 SessionTabHelper* session_tab_helper =
894 SessionTabHelper::FromWebContents(contents); 897 SessionTabHelper::FromWebContents(contents);
895 session_tab_helper->SetWindowID(session_id()); 898 session_tab_helper->SetWindowID(session_id());
896 899
897 content::NotificationService::current()->Notify( 900 content::NotificationService::current()->Notify(
898 chrome::NOTIFICATION_TAB_PARENTED, 901 chrome::NOTIFICATION_TAB_PARENTED,
899 content::Source<content::WebContents>(contents), 902 content::Source<content::WebContents>(contents),
900 content::NotificationService::NoDetails()); 903 content::NotificationService::NoDetails());
901 904
902 SyncHistoryWithTabs(index); 905 SyncHistoryWithTabs(index);
(...skipping 23 matching lines...) Expand all
926 SessionServiceFactory::GetForProfile(profile_); 929 SessionServiceFactory::GetForProfile(profile_);
927 if (session_service) 930 if (session_service)
928 session_service->TabClosing(contents); 931 session_service->TabClosing(contents);
929 content::NotificationService::current()->Notify( 932 content::NotificationService::current()->Notify(
930 chrome::NOTIFICATION_TAB_CLOSING, 933 chrome::NOTIFICATION_TAB_CLOSING,
931 content::Source<NavigationController>(&contents->GetController()), 934 content::Source<NavigationController>(&contents->GetController()),
932 content::NotificationService::NoDetails()); 935 content::NotificationService::NoDetails());
933 936
934 // Sever the WebContents' connection back to us. 937 // Sever the WebContents' connection back to us.
935 SetAsDelegate(contents, NULL); 938 SetAsDelegate(contents, NULL);
939 ClearAsObserver(contents);
936 } 940 }
937 941
938 void Browser::TabDetachedAt(WebContents* contents, int index) { 942 void Browser::TabDetachedAt(WebContents* contents, int index) {
939 // TabDetachedAt is called before TabStripModel has updated the 943 // TabDetachedAt is called before TabStripModel has updated the
940 // active index. 944 // active index.
941 int old_active_index = tab_strip_model_->active_index(); 945 int old_active_index = tab_strip_model_->active_index();
942 if (index < old_active_index && !tab_strip_model_->closing_all()) { 946 if (index < old_active_index && !tab_strip_model_->closing_all()) {
943 SessionService* session_service = 947 SessionService* session_service =
944 SessionServiceFactory::GetForProfileIfExisting(profile_); 948 SessionServiceFactory::GetForProfileIfExisting(profile_);
945 if (session_service) 949 if (session_service)
(...skipping 1228 matching lines...) Expand 10 before | Expand all | Expand 10 after
2174 weak_factory_.GetWeakPtr())); 2178 weak_factory_.GetWeakPtr()));
2175 2179
2176 // Return false so the browser does not close. We'll close if the user 2180 // Return false so the browser does not close. We'll close if the user
2177 // confirms in the dialog. 2181 // confirms in the dialog.
2178 return false; 2182 return false;
2179 } 2183 }
2180 2184
2181 /////////////////////////////////////////////////////////////////////////////// 2185 ///////////////////////////////////////////////////////////////////////////////
2182 // Browser, Assorted utility functions (private): 2186 // Browser, Assorted utility functions (private):
2183 2187
2188 void Browser::SetAsObserver(WebContents* web_contents) {
2189 ZoomController::FromWebContents(web_contents)->AddObserver(this);
2190 }
2191
2192 void Browser::ClearAsObserver(WebContents* web_contents) {
2193 ZoomController::FromWebContents(web_contents)->RemoveObserver(this);
2194 }
2195
2184 void Browser::SetAsDelegate(WebContents* web_contents, Browser* delegate) { 2196 void Browser::SetAsDelegate(WebContents* web_contents, Browser* delegate) {
2185 // WebContents... 2197 // WebContents...
2186 web_contents->SetDelegate(delegate); 2198 web_contents->SetDelegate(delegate);
2187 2199
2188 // ...and all the helpers. 2200 // ...and all the helpers.
2189 BookmarkTabHelper::FromWebContents(web_contents)->set_delegate(delegate); 2201 BookmarkTabHelper::FromWebContents(web_contents)->set_delegate(delegate);
2190 WebContentsModalDialogManager::FromWebContents(web_contents)-> 2202 WebContentsModalDialogManager::FromWebContents(web_contents)->
2191 SetDelegate(delegate); 2203 SetDelegate(delegate);
2192 CoreTabHelper::FromWebContents(web_contents)->set_delegate(delegate); 2204 CoreTabHelper::FromWebContents(web_contents)->set_delegate(delegate);
2193 SearchEngineTabHelper::FromWebContents(web_contents)->set_delegate(delegate); 2205 SearchEngineTabHelper::FromWebContents(web_contents)->set_delegate(delegate);
2194 SearchTabHelper::FromWebContents(web_contents)->set_delegate(delegate); 2206 SearchTabHelper::FromWebContents(web_contents)->set_delegate(delegate);
2195 ZoomController::FromWebContents(web_contents)->set_observer(delegate);
2196 ChromeTranslateClient* chrome_translate_client = 2207 ChromeTranslateClient* chrome_translate_client =
2197 ChromeTranslateClient::FromWebContents(web_contents); 2208 ChromeTranslateClient::FromWebContents(web_contents);
2198 chrome_translate_client->translate_driver().set_observer( 2209 chrome_translate_client->translate_driver().set_observer(
2199 delegate ? delegate->translate_driver_observer_.get() : NULL); 2210 delegate ? delegate->translate_driver_observer_.get() : NULL);
2200 } 2211 }
2201 2212
2202 void Browser::CloseFrame() { 2213 void Browser::CloseFrame() {
2203 window_->Close(); 2214 window_->Close();
2204 } 2215 }
2205 2216
2206 void Browser::TabDetachedAtImpl(content::WebContents* contents, 2217 void Browser::TabDetachedAtImpl(content::WebContents* contents,
2207 int index, 2218 int index,
2208 DetachType type) { 2219 DetachType type) {
2209 if (type == DETACH_TYPE_DETACH) { 2220 if (type == DETACH_TYPE_DETACH) {
2210 // Save the current location bar state, but only if the tab being detached 2221 // Save the current location bar state, but only if the tab being detached
2211 // is the selected tab. Because saving state can conditionally revert the 2222 // is the selected tab. Because saving state can conditionally revert the
2212 // location bar, saving the current tab's location bar state to a 2223 // location bar, saving the current tab's location bar state to a
2213 // non-selected tab can corrupt both tabs. 2224 // non-selected tab can corrupt both tabs.
2214 if (contents == tab_strip_model_->GetActiveWebContents()) { 2225 if (contents == tab_strip_model_->GetActiveWebContents()) {
2215 LocationBar* location_bar = window()->GetLocationBar(); 2226 LocationBar* location_bar = window()->GetLocationBar();
2216 if (location_bar) 2227 if (location_bar)
2217 location_bar->SaveStateToContents(contents); 2228 location_bar->SaveStateToContents(contents);
2218 } 2229 }
2219 2230
2220 if (!tab_strip_model_->closing_all()) 2231 if (!tab_strip_model_->closing_all())
2221 SyncHistoryWithTabs(0); 2232 SyncHistoryWithTabs(0);
2222 } 2233 }
2223 2234
2224 SetAsDelegate(contents, NULL); 2235 SetAsDelegate(contents, NULL);
2236 ClearAsObserver(contents);
2225 RemoveScheduledUpdatesFor(contents); 2237 RemoveScheduledUpdatesFor(contents);
2226 2238
2227 if (find_bar_controller_.get() && index == tab_strip_model_->active_index()) { 2239 if (find_bar_controller_.get() && index == tab_strip_model_->active_index()) {
2228 find_bar_controller_->ChangeWebContents(NULL); 2240 find_bar_controller_->ChangeWebContents(NULL);
2229 } 2241 }
2230 2242
2231 // Stop observing search model changes for this tab. 2243 // Stop observing search model changes for this tab.
2232 search_delegate_->OnTabDetached(contents); 2244 search_delegate_->OnTabDetached(contents);
2233 2245
2234 for (size_t i = 0; i < interstitial_observers_.size(); i++) { 2246 for (size_t i = 0; i < interstitial_observers_.size(); i++) {
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
2417 if (contents && !allow_js_access) { 2429 if (contents && !allow_js_access) {
2418 contents->web_contents()->GetController().LoadURL( 2430 contents->web_contents()->GetController().LoadURL(
2419 target_url, 2431 target_url,
2420 content::Referrer(), 2432 content::Referrer(),
2421 content::PAGE_TRANSITION_LINK, 2433 content::PAGE_TRANSITION_LINK,
2422 std::string()); // No extra headers. 2434 std::string()); // No extra headers.
2423 } 2435 }
2424 2436
2425 return contents != NULL; 2437 return contents != NULL;
2426 } 2438 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698