Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/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 // OS_WIN | 10 #endif // OS_WIN |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 #include "net/cookies/cookie_monster.h" | 187 #include "net/cookies/cookie_monster.h" |
| 188 #include "net/url_request/url_request_context.h" | 188 #include "net/url_request/url_request_context.h" |
| 189 #include "ui/base/animation/animation.h" | 189 #include "ui/base/animation/animation.h" |
| 190 #include "ui/base/dialogs/selected_file_info.h" | 190 #include "ui/base/dialogs/selected_file_info.h" |
| 191 #include "ui/base/l10n/l10n_util.h" | 191 #include "ui/base/l10n/l10n_util.h" |
| 192 #include "ui/gfx/point.h" | 192 #include "ui/gfx/point.h" |
| 193 #include "webkit/glue/web_intent_data.h" | 193 #include "webkit/glue/web_intent_data.h" |
| 194 #include "webkit/glue/web_intent_service_data.h" | 194 #include "webkit/glue/web_intent_service_data.h" |
| 195 #include "webkit/glue/webkit_glue.h" | 195 #include "webkit/glue/webkit_glue.h" |
| 196 #include "webkit/glue/window_open_disposition.h" | 196 #include "webkit/glue/window_open_disposition.h" |
| 197 #include "webkit/plugins/npapi/plugin_group.h" | |
| 198 #include "webkit/plugins/npapi/plugin_list.h" | |
| 197 #include "webkit/plugins/webplugininfo.h" | 199 #include "webkit/plugins/webplugininfo.h" |
| 198 | 200 |
| 199 #if defined(OS_WIN) | 201 #if defined(OS_WIN) |
| 200 #include "base/win/metro.h" | 202 #include "base/win/metro.h" |
| 201 #include "chrome/browser/autofill/autofill_ie_toolbar_import_win.h" | 203 #include "chrome/browser/autofill/autofill_ie_toolbar_import_win.h" |
| 202 #include "chrome/browser/shell_integration.h" | 204 #include "chrome/browser/shell_integration.h" |
| 203 #include "chrome/browser/ssl/ssl_error_info.h" | 205 #include "chrome/browser/ssl/ssl_error_info.h" |
| 204 #include "chrome/browser/task_manager/task_manager.h" | 206 #include "chrome/browser/task_manager/task_manager.h" |
| 205 #include "chrome/browser/ui/view_ids.h" | 207 #include "chrome/browser/ui/view_ids.h" |
| 206 #include "ui/base/win/shell.h" | 208 #include "ui/base/win/shell.h" |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 232 namespace { | 234 namespace { |
| 233 | 235 |
| 234 // The URL to be loaded to display the "Report a broken page" form. | 236 // The URL to be loaded to display the "Report a broken page" form. |
| 235 const char kBrokenPageUrl[] = | 237 const char kBrokenPageUrl[] = |
| 236 "https://www.google.com/support/chrome/bin/request.py?contact_type=" | 238 "https://www.google.com/support/chrome/bin/request.py?contact_type=" |
| 237 "broken_website&format=inproduct&p.page_title=$1&p.page_url=$2"; | 239 "broken_website&format=inproduct&p.page_title=$1&p.page_url=$2"; |
| 238 | 240 |
| 239 // The URL for the privacy dashboard. | 241 // The URL for the privacy dashboard. |
| 240 const char kPrivacyDashboardUrl[] = "https://www.google.com/dashboard"; | 242 const char kPrivacyDashboardUrl[] = "https://www.google.com/dashboard"; |
| 241 | 243 |
| 244 // The URL for the "learn more" article about the PPAPI broker. | |
| 245 const char kPpapiBrokerLearnMoreUrl[] = | |
| 246 "https://support.google.com/chrome/?p=ib_pepper_broker"; | |
| 247 | |
| 242 // How long we wait before updating the browser chrome while loading a page. | 248 // How long we wait before updating the browser chrome while loading a page. |
| 243 const int kUIUpdateCoalescingTimeMS = 200; | 249 const int kUIUpdateCoalescingTimeMS = 200; |
| 244 | 250 |
| 245 bool AllowPanels(const std::string& app_name) { | 251 bool AllowPanels(const std::string& app_name) { |
| 246 return PanelManager::ShouldUsePanels( | 252 return PanelManager::ShouldUsePanels( |
| 247 web_app::GetExtensionIdFromApplicationName(app_name)); | 253 web_app::GetExtensionIdFromApplicationName(app_name)); |
| 248 } | 254 } |
| 249 | 255 |
| 250 BrowserWindow* CreateBrowserWindow(Browser* browser) { | 256 BrowserWindow* CreateBrowserWindow(Browser* browser) { |
| 251 #if !defined(USE_ASH) | 257 #if !defined(USE_ASH) |
| 252 if (browser->is_type_panel()) | 258 if (browser->is_type_panel()) |
| 253 return PanelManager::GetInstance()->CreatePanel(browser)->browser_window(); | 259 return PanelManager::GetInstance()->CreatePanel(browser)->browser_window(); |
| 254 #endif | 260 #endif |
| 255 return BrowserWindow::CreateBrowserWindow(browser); | 261 return BrowserWindow::CreateBrowserWindow(browser); |
| 256 } | 262 } |
| 257 | 263 |
| 258 #if defined(OS_CHROMEOS) | 264 #if defined(OS_CHROMEOS) |
| 259 chrome::HostDesktopType kDefaultHostDesktopType = chrome::HOST_DESKTOP_TYPE_ASH; | 265 chrome::HostDesktopType kDefaultHostDesktopType = chrome::HOST_DESKTOP_TYPE_ASH; |
| 260 #else | 266 #else |
| 261 chrome::HostDesktopType kDefaultHostDesktopType = | 267 chrome::HostDesktopType kDefaultHostDesktopType = |
| 262 chrome::HOST_DESKTOP_TYPE_NATIVE; | 268 chrome::HOST_DESKTOP_TYPE_NATIVE; |
| 263 #endif | 269 #endif |
| 264 | 270 |
| 265 | 271 |
| 272 class PpapiBrokerPermissionInfoBarDelegate : public ConfirmInfoBarDelegate { | |
|
sky
2012/08/14 15:52:12
Move this into its own .h/.cc
Bernhard Bauer
2012/08/14 23:36:24
Done.
| |
| 273 public: | |
| 274 PpapiBrokerPermissionInfoBarDelegate( | |
| 275 InfoBarTabHelper* helper, | |
| 276 const GURL& url, | |
| 277 const FilePath& plugin_path, | |
| 278 const std::string& languages, | |
| 279 HostContentSettingsMap* content_settings, | |
| 280 const base::Callback<void(bool)>& callback); | |
| 281 virtual ~PpapiBrokerPermissionInfoBarDelegate(); | |
| 282 | |
| 283 // ConfirmInfoBarDelegate: | |
| 284 virtual string16 GetMessageText() const OVERRIDE; | |
| 285 virtual int GetButtons() const OVERRIDE; | |
| 286 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | |
| 287 virtual bool Accept() OVERRIDE; | |
| 288 virtual bool Cancel() OVERRIDE; | |
| 289 virtual string16 GetLinkText() const OVERRIDE; | |
| 290 virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; | |
| 291 virtual gfx::Image* GetIcon() const OVERRIDE; | |
| 292 | |
| 293 private: | |
| 294 GURL url_; | |
|
sky
2012/08/14 15:52:12
Make members const where applicable.
Bernhard Bauer
2012/08/14 23:36:24
Done.
| |
| 295 FilePath plugin_path_; | |
| 296 std::string languages_; | |
| 297 HostContentSettingsMap* content_settings_; | |
| 298 base::Callback<void(bool)> callback_; | |
| 299 }; | |
|
sky
2012/08/14 15:52:12
DISALLOW_...
Bernhard Bauer
2012/08/14 23:36:24
Done.
| |
| 300 | |
| 301 PpapiBrokerPermissionInfoBarDelegate::PpapiBrokerPermissionInfoBarDelegate( | |
| 302 InfoBarTabHelper* helper, | |
| 303 const GURL& url, | |
| 304 const FilePath& plugin_path, | |
| 305 const std::string& languages, | |
| 306 HostContentSettingsMap* content_settings, | |
| 307 const base::Callback<void(bool)>& callback) | |
| 308 : ConfirmInfoBarDelegate(helper), | |
| 309 url_(url), | |
| 310 plugin_path_(plugin_path), | |
| 311 languages_(languages), | |
| 312 content_settings_(content_settings), | |
| 313 callback_(callback) { | |
| 314 } | |
| 315 | |
| 316 PpapiBrokerPermissionInfoBarDelegate::~PpapiBrokerPermissionInfoBarDelegate() { | |
| 317 if (!callback_.is_null()) | |
| 318 callback_.Run(false); | |
| 319 } | |
| 320 | |
| 321 string16 PpapiBrokerPermissionInfoBarDelegate::GetMessageText() const { | |
| 322 content::PluginService* plugin_service = | |
| 323 content::PluginService::GetInstance(); | |
| 324 webkit::WebPluginInfo plugin; | |
| 325 bool success = plugin_service->GetPluginInfoByPath(plugin_path_, &plugin); | |
| 326 DCHECK(success); | |
| 327 scoped_ptr<webkit::npapi::PluginGroup> plugin_group( | |
| 328 plugin_service->GetPluginList()->GetPluginGroup(plugin)); | |
| 329 return l10n_util::GetStringFUTF16(IDS_PPAPI_BROKER_INFOBAR_QUESTION, | |
| 330 plugin_group->GetGroupName(), | |
| 331 net::FormatUrl(url_, languages_)); | |
| 332 } | |
| 333 | |
| 334 int PpapiBrokerPermissionInfoBarDelegate::GetButtons() const { | |
| 335 return BUTTON_OK | BUTTON_CANCEL; | |
| 336 } | |
| 337 | |
| 338 string16 PpapiBrokerPermissionInfoBarDelegate::GetButtonLabel( | |
| 339 InfoBarButton button) const { | |
| 340 switch (button) { | |
| 341 case BUTTON_OK: | |
| 342 return l10n_util::GetStringUTF16(IDS_PPAPI_BROKER_ALLOW_BUTTON); | |
| 343 case BUTTON_CANCEL: | |
| 344 return l10n_util::GetStringUTF16(IDS_PPAPI_BROKER_DENY_BUTTON); | |
| 345 default: | |
| 346 NOTREACHED(); | |
| 347 return string16(); | |
| 348 } | |
| 349 } | |
| 350 | |
| 351 bool PpapiBrokerPermissionInfoBarDelegate::Accept() { | |
| 352 callback_.Run(true); | |
| 353 callback_ = base::Callback<void(bool)>(); | |
| 354 content_settings_->SetContentSetting( | |
| 355 ContentSettingsPattern::FromURLNoWildcard(url_), | |
| 356 ContentSettingsPattern::Wildcard(), | |
| 357 CONTENT_SETTINGS_TYPE_PPAPI_BROKER, | |
| 358 std::string(), CONTENT_SETTING_ALLOW); | |
| 359 return true; | |
| 360 } | |
| 361 | |
| 362 bool PpapiBrokerPermissionInfoBarDelegate::Cancel() { | |
| 363 callback_.Run(false); | |
| 364 callback_ = base::Callback<void(bool)>(); | |
| 365 return true; | |
| 366 } | |
| 367 | |
| 368 string16 PpapiBrokerPermissionInfoBarDelegate::GetLinkText() const { | |
| 369 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); | |
| 370 } | |
| 371 | |
| 372 bool PpapiBrokerPermissionInfoBarDelegate::LinkClicked( | |
| 373 WindowOpenDisposition disposition) { | |
| 374 OpenURLParams params( | |
| 375 GURL(kPpapiBrokerLearnMoreUrl), Referrer(), | |
| 376 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, | |
| 377 content::PAGE_TRANSITION_LINK, | |
| 378 false); | |
| 379 owner()->web_contents()->OpenURL(params); | |
| 380 return false; | |
| 381 } | |
| 382 | |
| 383 gfx::Image* PpapiBrokerPermissionInfoBarDelegate::GetIcon() const { | |
| 384 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed( | |
| 385 IDR_INFOBAR_PLUGIN_INSTALL); | |
| 386 } | |
| 387 | |
| 266 } // namespace | 388 } // namespace |
| 267 | 389 |
| 268 //////////////////////////////////////////////////////////////////////////////// | 390 //////////////////////////////////////////////////////////////////////////////// |
| 269 // Browser, CreateParams: | 391 // Browser, CreateParams: |
| 270 | 392 |
| 271 Browser::CreateParams::CreateParams() | 393 Browser::CreateParams::CreateParams() |
| 272 : type(TYPE_TABBED), | 394 : type(TYPE_TABBED), |
| 273 profile(NULL), | 395 profile(NULL), |
| 274 host_desktop_type(kDefaultHostDesktopType), | 396 host_desktop_type(kDefaultHostDesktopType), |
| 275 app_type(APP_TYPE_HOST), | 397 app_type(APP_TYPE_HOST), |
| (...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 973 InfoBarDelegate* infobar = | 1095 InfoBarDelegate* infobar = |
| 974 new MediaStreamInfoBarDelegate(infobar_helper, controller.release()); | 1096 new MediaStreamInfoBarDelegate(infobar_helper, controller.release()); |
| 975 if (old_infobar) | 1097 if (old_infobar) |
| 976 infobar_helper->ReplaceInfoBar(old_infobar, infobar); | 1098 infobar_helper->ReplaceInfoBar(old_infobar, infobar); |
| 977 else | 1099 else |
| 978 infobar_helper->AddInfoBar(infobar); | 1100 infobar_helper->AddInfoBar(infobar); |
| 979 } | 1101 } |
| 980 } | 1102 } |
| 981 | 1103 |
| 982 // static | 1104 // static |
| 983 void Browser::RequestPpapiBrokerPermissionHelper( | 1105 void Browser::RequestPpapiBrokerPermissionHelper( |
|
sky
2012/08/14 15:52:12
Why does this need to live in Browser?
Bernhard Bauer
2012/08/14 23:36:24
Browser is the "standard" implementation of WebCon
sky
2012/08/15 02:29:34
Who is calling it directly in browser.cc though? I
Bernhard Bauer
2012/08/15 09:36:53
Browser::RequestPpapiBrokerPermission() does, whic
| |
| 984 WebContents* web_contents, | 1106 WebContents* web_contents, |
| 985 const GURL& url, | 1107 const GURL& url, |
| 986 const FilePath& plugin_path, | 1108 const FilePath& plugin_path, |
| 987 const base::Callback<void(bool)>& callback) { | 1109 const base::Callback<void(bool)>& callback) { |
| 988 // TODO(bauerb): Request permission. | 1110 TabContents* tab = TabContents::FromWebContents(web_contents); |
| 989 callback.Run(true); | 1111 if (!tab) { |
| 1112 callback.Run(false); | |
| 1113 return; | |
| 1114 } | |
| 1115 | |
| 1116 Profile* profile = tab->profile(); | |
| 1117 // Disallow broker access in incognito mode. | |
| 1118 if (profile->IsOffTheRecord() || Profile::IsGuestSession()) { | |
| 1119 callback.Run(false); | |
| 1120 return; | |
| 1121 } | |
| 1122 | |
| 1123 HostContentSettingsMap* content_settings = | |
| 1124 profile->GetHostContentSettingsMap(); | |
| 1125 ContentSetting setting = | |
| 1126 content_settings->GetContentSetting(url, url, | |
| 1127 CONTENT_SETTINGS_TYPE_PPAPI_BROKER, | |
| 1128 std::string()); | |
| 1129 switch (setting) { | |
| 1130 case CONTENT_SETTING_ALLOW: { | |
| 1131 callback.Run(true); | |
| 1132 break; | |
| 1133 } | |
| 1134 case CONTENT_SETTING_BLOCK: { | |
| 1135 callback.Run(false); | |
| 1136 break; | |
| 1137 } | |
| 1138 case CONTENT_SETTING_ASK: { | |
| 1139 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper(); | |
| 1140 std::string languages = | |
| 1141 profile->GetPrefs()->GetString(prefs::kAcceptLanguages); | |
| 1142 infobar_helper->AddInfoBar( | |
| 1143 new PpapiBrokerPermissionInfoBarDelegate( | |
| 1144 infobar_helper, url, plugin_path, languages, content_settings, | |
| 1145 callback)); | |
| 1146 break; | |
| 1147 } | |
| 1148 default: | |
| 1149 NOTREACHED(); | |
| 1150 } | |
| 990 } | 1151 } |
| 991 | 1152 |
| 992 void Browser::UpdateUIForNavigationInTab(TabContents* contents, | 1153 void Browser::UpdateUIForNavigationInTab(TabContents* contents, |
| 993 content::PageTransition transition, | 1154 content::PageTransition transition, |
| 994 bool user_initiated) { | 1155 bool user_initiated) { |
| 995 tab_strip_model_->TabNavigating(contents, transition); | 1156 tab_strip_model_->TabNavigating(contents, transition); |
| 996 | 1157 |
| 997 bool contents_is_selected = contents == chrome::GetActiveTabContents(this); | 1158 bool contents_is_selected = contents == chrome::GetActiveTabContents(this); |
| 998 if (user_initiated && contents_is_selected && window()->GetLocationBar()) { | 1159 if (user_initiated && contents_is_selected && window()->GetLocationBar()) { |
| 999 // Forcibly reset the location bar if the url is going to change in the | 1160 // Forcibly reset the location bar if the url is going to change in the |
| (...skipping 1338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2338 if (contents && !allow_js_access) { | 2499 if (contents && !allow_js_access) { |
| 2339 contents->web_contents()->GetController().LoadURL( | 2500 contents->web_contents()->GetController().LoadURL( |
| 2340 target_url, | 2501 target_url, |
| 2341 content::Referrer(), | 2502 content::Referrer(), |
| 2342 content::PAGE_TRANSITION_LINK, | 2503 content::PAGE_TRANSITION_LINK, |
| 2343 std::string()); // No extra headers. | 2504 std::string()); // No extra headers. |
| 2344 } | 2505 } |
| 2345 | 2506 |
| 2346 return contents != NULL; | 2507 return contents != NULL; |
| 2347 } | 2508 } |
| OLD | NEW |