Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/app_list/start_page_service.h" | 5 #include "chrome/browser/ui/app_list/start_page_service.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/json/json_string_value_serializer.h" | 11 #include "base/json/json_string_value_serializer.h" |
| 12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
| 13 #include "base/metrics/user_metrics.h" | 13 #include "base/metrics/user_metrics.h" |
| 14 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
| 15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/chrome_notification_types.h" | 16 #include "chrome/browser/chrome_notification_types.h" |
| 17 #include "chrome/browser/google/google_profile_helper.h" | 17 #include "chrome/browser/google/google_profile_helper.h" |
| 18 #include "chrome/browser/media/media_stream_infobar_delegate.h" | 18 #include "chrome/browser/media/media_stream_infobar_delegate.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/search/hotword_service.h" | 20 #include "chrome/browser/search/hotword_service.h" |
| 21 #include "chrome/browser/search/hotword_service_factory.h" | 21 #include "chrome/browser/search/hotword_service_factory.h" |
| 22 #include "chrome/browser/ui/app_list/speech_auth_helper.h" | 22 #include "chrome/browser/ui/app_list/speech_auth_helper.h" |
| 23 #include "chrome/browser/ui/app_list/speech_recognizer.h" | 23 #include "chrome/browser/ui/app_list/speech_recognizer.h" |
| 24 #include "chrome/browser/ui/app_list/start_page_observer.h" | 24 #include "chrome/browser/ui/app_list/start_page_observer.h" |
| 25 #include "chrome/browser/ui/app_list/start_page_service_factory.h" | 25 #include "chrome/browser/ui/app_list/start_page_service_factory.h" |
| 26 #include "chrome/browser/ui/browser_navigator.h" | |
| 27 #include "chrome/browser/ui/browser_tabstrip.h" | |
| 28 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | |
| 26 #include "chrome/common/chrome_switches.h" | 29 #include "chrome/common/chrome_switches.h" |
| 27 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
| 28 #include "chrome/common/url_constants.h" | 31 #include "chrome/common/url_constants.h" |
| 29 #include "components/google/core/browser/google_util.h" | 32 #include "components/google/core/browser/google_util.h" |
| 30 #include "components/ui/zoom/zoom_controller.h" | 33 #include "components/ui/zoom/zoom_controller.h" |
| 31 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
| 32 #include "content/public/browser/notification_details.h" | 35 #include "content/public/browser/notification_details.h" |
| 33 #include "content/public/browser/notification_observer.h" | 36 #include "content/public/browser/notification_observer.h" |
| 34 #include "content/public/browser/notification_registrar.h" | 37 #include "content/public/browser/notification_registrar.h" |
| 35 #include "content/public/browser/notification_service.h" | 38 #include "content/public/browser/notification_service.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 | 103 |
| 101 StartPageService* service_; // Owner of this class. | 104 StartPageService* service_; // Owner of this class. |
| 102 content::NotificationRegistrar registrar_; | 105 content::NotificationRegistrar registrar_; |
| 103 | 106 |
| 104 DISALLOW_COPY_AND_ASSIGN(ProfileDestroyObserver); | 107 DISALLOW_COPY_AND_ASSIGN(ProfileDestroyObserver); |
| 105 }; | 108 }; |
| 106 | 109 |
| 107 class StartPageService::StartPageWebContentsDelegate | 110 class StartPageService::StartPageWebContentsDelegate |
| 108 : public content::WebContentsDelegate { | 111 : public content::WebContentsDelegate { |
| 109 public: | 112 public: |
| 110 StartPageWebContentsDelegate() {} | 113 explicit StartPageWebContentsDelegate(Profile* profile) : profile_(profile) {} |
| 111 ~StartPageWebContentsDelegate() override {} | 114 ~StartPageWebContentsDelegate() override {} |
| 112 | 115 |
| 113 void RequestMediaAccessPermission( | 116 void RequestMediaAccessPermission( |
| 114 content::WebContents* web_contents, | 117 content::WebContents* web_contents, |
| 115 const content::MediaStreamRequest& request, | 118 const content::MediaStreamRequest& request, |
| 116 const content::MediaResponseCallback& callback) override { | 119 const content::MediaResponseCallback& callback) override { |
| 117 if (MediaStreamInfoBarDelegate::Create(web_contents, request, callback)) | 120 if (MediaStreamInfoBarDelegate::Create(web_contents, request, callback)) |
| 118 NOTREACHED() << "Media stream not allowed for WebUI"; | 121 NOTREACHED() << "Media stream not allowed for WebUI"; |
| 119 } | 122 } |
| 120 | 123 |
| 121 bool CheckMediaAccessPermission(content::WebContents* web_contents, | 124 bool CheckMediaAccessPermission(content::WebContents* web_contents, |
| 122 const GURL& security_origin, | 125 const GURL& security_origin, |
| 123 content::MediaStreamType type) override { | 126 content::MediaStreamType type) override { |
| 124 return MediaCaptureDevicesDispatcher::GetInstance() | 127 return MediaCaptureDevicesDispatcher::GetInstance() |
| 125 ->CheckMediaAccessPermission(web_contents, security_origin, type); | 128 ->CheckMediaAccessPermission(web_contents, security_origin, type); |
| 126 } | 129 } |
| 127 | 130 |
| 131 void AddNewContents(content::WebContents* source, | |
| 132 content::WebContents* new_contents, | |
| 133 WindowOpenDisposition disposition, | |
| 134 const gfx::Rect& initial_pos, | |
| 135 bool user_gesture, | |
| 136 bool* was_blocked) override { | |
| 137 chrome::ScopedTabbedBrowserDisplayer displayer( | |
| 138 profile_, chrome::GetActiveDesktop()); | |
| 139 // Force all links to open in a new tab, even if they were trying to open a | |
| 140 // new window. | |
| 141 disposition = | |
| 142 disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; | |
| 143 chrome::AddWebContents(displayer.browser(), | |
| 144 NULL, | |
|
Matt Giuca
2015/02/03 07:08:50
nullptr
calamity
2015/02/04 03:16:22
Done.
| |
| 145 new_contents, | |
| 146 disposition, | |
| 147 initial_pos, | |
| 148 user_gesture, | |
| 149 was_blocked); | |
| 150 } | |
| 151 | |
| 152 content::WebContents* OpenURLFromTab( | |
| 153 content::WebContents* source, | |
| 154 const content::OpenURLParams& params) override { | |
| 155 // Force all links to open in a new tab, even if they were trying to open a | |
| 156 // window. | |
| 157 chrome::NavigateParams new_tab_params( | |
| 158 static_cast<Browser*>(NULL), params.url, params.transition); | |
|
Matt Giuca
2015/02/03 07:08:50
nullptr
calamity
2015/02/04 03:16:22
Done.
| |
| 159 if (params.disposition == NEW_BACKGROUND_TAB) { | |
| 160 new_tab_params.disposition = NEW_BACKGROUND_TAB; | |
| 161 } else { | |
| 162 new_tab_params.disposition = NEW_FOREGROUND_TAB; | |
| 163 new_tab_params.window_action = chrome::NavigateParams::SHOW_WINDOW; | |
| 164 } | |
| 165 | |
| 166 new_tab_params.initiating_profile = profile_; | |
| 167 chrome::Navigate(&new_tab_params); | |
| 168 | |
| 169 return new_tab_params.target_contents; | |
| 170 } | |
| 171 | |
| 128 private: | 172 private: |
| 173 Profile* profile_; | |
| 174 | |
| 129 DISALLOW_COPY_AND_ASSIGN(StartPageWebContentsDelegate); | 175 DISALLOW_COPY_AND_ASSIGN(StartPageWebContentsDelegate); |
| 130 }; | 176 }; |
| 131 | 177 |
| 132 #if defined(OS_CHROMEOS) | 178 #if defined(OS_CHROMEOS) |
| 133 | 179 |
| 134 class StartPageService::AudioStatus | 180 class StartPageService::AudioStatus |
| 135 : public chromeos::CrasAudioHandler::AudioObserver { | 181 : public chromeos::CrasAudioHandler::AudioObserver { |
| 136 public: | 182 public: |
| 137 explicit AudioStatus(StartPageService* start_page_service) | 183 explicit AudioStatus(StartPageService* start_page_service) |
| 138 : start_page_service_(start_page_service) { | 184 : start_page_service_(start_page_service) { |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 491 for (const auto& cb : pending_webui_callbacks_) | 537 for (const auto& cb : pending_webui_callbacks_) |
| 492 cb.Run(); | 538 cb.Run(); |
| 493 pending_webui_callbacks_.clear(); | 539 pending_webui_callbacks_.clear(); |
| 494 | 540 |
| 495 FetchDoodleJson(); | 541 FetchDoodleJson(); |
| 496 } | 542 } |
| 497 | 543 |
| 498 void StartPageService::LoadContents() { | 544 void StartPageService::LoadContents() { |
| 499 contents_.reset(content::WebContents::Create( | 545 contents_.reset(content::WebContents::Create( |
| 500 content::WebContents::CreateParams(profile_))); | 546 content::WebContents::CreateParams(profile_))); |
| 501 contents_delegate_.reset(new StartPageWebContentsDelegate()); | 547 contents_delegate_.reset(new StartPageWebContentsDelegate(profile_)); |
| 502 contents_->SetDelegate(contents_delegate_.get()); | 548 contents_->SetDelegate(contents_delegate_.get()); |
| 503 | 549 |
| 504 // The ZoomController needs to be created before the web contents is observed | 550 // The ZoomController needs to be created before the web contents is observed |
| 505 // by this object. Otherwise it will react to DidNavigateMainFrame after this | 551 // by this object. Otherwise it will react to DidNavigateMainFrame after this |
| 506 // object does, resetting the zoom mode in the process. | 552 // object does, resetting the zoom mode in the process. |
| 507 ui_zoom::ZoomController::CreateForWebContents(contents_.get()); | 553 ui_zoom::ZoomController::CreateForWebContents(contents_.get()); |
| 508 Observe(contents_.get()); | 554 Observe(contents_.get()); |
| 509 | 555 |
| 510 contents_->GetController().LoadURL( | 556 contents_->GetController().LoadURL( |
| 511 GURL(chrome::kChromeUIAppListStartPageURL), | 557 GURL(chrome::kChromeUIAppListStartPageURL), |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 570 | 616 |
| 571 // Check for a new doodle. | 617 // Check for a new doodle. |
| 572 content::BrowserThread::PostDelayedTask( | 618 content::BrowserThread::PostDelayedTask( |
| 573 content::BrowserThread::UI, FROM_HERE, | 619 content::BrowserThread::UI, FROM_HERE, |
| 574 base::Bind(&StartPageService::FetchDoodleJson, | 620 base::Bind(&StartPageService::FetchDoodleJson, |
| 575 weak_factory_.GetWeakPtr()), | 621 weak_factory_.GetWeakPtr()), |
| 576 recheck_delay); | 622 recheck_delay); |
| 577 } | 623 } |
| 578 | 624 |
| 579 } // namespace app_list | 625 } // namespace app_list |
| OLD | NEW |