| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "athena/content/web_activity.h" | 5 #include "athena/content/web_activity.h" |
| 6 | 6 |
| 7 #include "athena/activity/public/activity_factory.h" | 7 #include "athena/activity/public/activity_factory.h" |
| 8 #include "athena/activity/public/activity_manager.h" | 8 #include "athena/activity/public/activity_manager.h" |
| 9 #include "athena/content/content_proxy.h" | 9 #include "athena/content/content_proxy.h" |
| 10 #include "athena/content/media_utils.h" | 10 #include "athena/content/media_utils.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 CMD_RELOAD_IGNORE_CACHE, | 45 CMD_RELOAD_IGNORE_CACHE, |
| 46 CMD_CLOSE, | 46 CMD_CLOSE, |
| 47 CMD_STOP, | 47 CMD_STOP, |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 explicit WebActivityController(WebActivity* owner_activity, | 50 explicit WebActivityController(WebActivity* owner_activity, |
| 51 views::WebView* web_view) | 51 views::WebView* web_view) |
| 52 : owner_activity_(owner_activity), | 52 : owner_activity_(owner_activity), |
| 53 web_view_(web_view), | 53 web_view_(web_view), |
| 54 reserved_accelerator_enabled_(true) {} | 54 reserved_accelerator_enabled_(true) {} |
| 55 virtual ~WebActivityController() {} | 55 ~WebActivityController() override {} |
| 56 | 56 |
| 57 // Installs accelerators for web activity. | 57 // Installs accelerators for web activity. |
| 58 void InstallAccelerators() { | 58 void InstallAccelerators() { |
| 59 accelerator_manager_ = AcceleratorManager::CreateForFocusManager( | 59 accelerator_manager_ = AcceleratorManager::CreateForFocusManager( |
| 60 web_view_->GetFocusManager()).Pass(); | 60 web_view_->GetFocusManager()).Pass(); |
| 61 const AcceleratorData accelerator_data[] = { | 61 const AcceleratorData accelerator_data[] = { |
| 62 {TRIGGER_ON_PRESS, ui::VKEY_R, ui::EF_CONTROL_DOWN, CMD_RELOAD, | 62 {TRIGGER_ON_PRESS, ui::VKEY_R, ui::EF_CONTROL_DOWN, CMD_RELOAD, |
| 63 AF_NONE}, | 63 AF_NONE}, |
| 64 {TRIGGER_ON_PRESS, ui::VKEY_BROWSER_REFRESH, ui::EF_NONE, CMD_RELOAD, | 64 {TRIGGER_ON_PRESS, ui::VKEY_BROWSER_REFRESH, ui::EF_NONE, CMD_RELOAD, |
| 65 AF_NONE}, | 65 AF_NONE}, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 } | 98 } |
| 99 | 99 |
| 100 void HandleKeyboardEvent(content::WebContents* source, | 100 void HandleKeyboardEvent(content::WebContents* source, |
| 101 const content::NativeWebKeyboardEvent& event) { | 101 const content::NativeWebKeyboardEvent& event) { |
| 102 unhandled_keyboard_event_handler_.HandleKeyboardEvent( | 102 unhandled_keyboard_event_handler_.HandleKeyboardEvent( |
| 103 event, web_view_->GetFocusManager()); | 103 event, web_view_->GetFocusManager()); |
| 104 } | 104 } |
| 105 | 105 |
| 106 private: | 106 private: |
| 107 // AcceleratorHandler: | 107 // AcceleratorHandler: |
| 108 virtual bool IsCommandEnabled(int command_id) const override { | 108 bool IsCommandEnabled(int command_id) const override { |
| 109 switch (command_id) { | 109 switch (command_id) { |
| 110 case CMD_RELOAD: | 110 case CMD_RELOAD: |
| 111 case CMD_RELOAD_IGNORE_CACHE: | 111 case CMD_RELOAD_IGNORE_CACHE: |
| 112 return true; | 112 return true; |
| 113 case CMD_BACK: | 113 case CMD_BACK: |
| 114 return web_view_->GetWebContents()->GetController().CanGoBack(); | 114 return web_view_->GetWebContents()->GetController().CanGoBack(); |
| 115 case CMD_FORWARD: | 115 case CMD_FORWARD: |
| 116 return web_view_->GetWebContents()->GetController().CanGoForward(); | 116 return web_view_->GetWebContents()->GetController().CanGoForward(); |
| 117 case CMD_CLOSE: | 117 case CMD_CLOSE: |
| 118 // TODO(oshima): check onbeforeunload handler. | 118 // TODO(oshima): check onbeforeunload handler. |
| 119 return true; | 119 return true; |
| 120 case CMD_STOP: | 120 case CMD_STOP: |
| 121 return web_view_->GetWebContents()->IsLoading(); | 121 return web_view_->GetWebContents()->IsLoading(); |
| 122 } | 122 } |
| 123 return false; | 123 return false; |
| 124 } | 124 } |
| 125 | 125 |
| 126 virtual bool OnAcceleratorFired(int command_id, | 126 bool OnAcceleratorFired(int command_id, |
| 127 const ui::Accelerator& accelerator) override { | 127 const ui::Accelerator& accelerator) override { |
| 128 switch (command_id) { | 128 switch (command_id) { |
| 129 case CMD_RELOAD: | 129 case CMD_RELOAD: |
| 130 web_view_->GetWebContents()->GetController().Reload(false); | 130 web_view_->GetWebContents()->GetController().Reload(false); |
| 131 return true; | 131 return true; |
| 132 case CMD_RELOAD_IGNORE_CACHE: | 132 case CMD_RELOAD_IGNORE_CACHE: |
| 133 web_view_->GetWebContents()->GetController().ReloadIgnoringCache(false); | 133 web_view_->GetWebContents()->GetController().ReloadIgnoringCache(false); |
| 134 return true; | 134 return true; |
| 135 case CMD_BACK: | 135 case CMD_BACK: |
| 136 web_view_->GetWebContents()->GetController().GoBack(); | 136 web_view_->GetWebContents()->GetController().GoBack(); |
| 137 return true; | 137 return true; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 182 |
| 183 AthenaWebView(content::WebContents* web_contents, | 183 AthenaWebView(content::WebContents* web_contents, |
| 184 WebActivity* owner_activity) | 184 WebActivity* owner_activity) |
| 185 : views::WebView(web_contents->GetBrowserContext()), | 185 : views::WebView(web_contents->GetBrowserContext()), |
| 186 controller_(new WebActivityController(owner_activity, this)), | 186 controller_(new WebActivityController(owner_activity, this)), |
| 187 owner_activity_(owner_activity) { | 187 owner_activity_(owner_activity) { |
| 188 scoped_ptr<content::WebContents> old_contents( | 188 scoped_ptr<content::WebContents> old_contents( |
| 189 SwapWebContents(scoped_ptr<content::WebContents>(web_contents))); | 189 SwapWebContents(scoped_ptr<content::WebContents>(web_contents))); |
| 190 } | 190 } |
| 191 | 191 |
| 192 virtual ~AthenaWebView() {} | 192 ~AthenaWebView() override {} |
| 193 | 193 |
| 194 void InstallAccelerators() { controller_->InstallAccelerators(); } | 194 void InstallAccelerators() { controller_->InstallAccelerators(); } |
| 195 | 195 |
| 196 void EvictContent() { | 196 void EvictContent() { |
| 197 scoped_ptr<content::WebContents> old_contents(SwapWebContents( | 197 scoped_ptr<content::WebContents> old_contents(SwapWebContents( |
| 198 scoped_ptr<content::WebContents>(content::WebContents::Create( | 198 scoped_ptr<content::WebContents>(content::WebContents::Create( |
| 199 content::WebContents::CreateParams(browser_context()))))); | 199 content::WebContents::CreateParams(browser_context()))))); |
| 200 // If there is a progress bar, we need to get rid of it now since its | 200 // If there is a progress bar, we need to get rid of it now since its |
| 201 // associated content, parent window and layers will disappear with evicting | 201 // associated content, parent window and layers will disappear with evicting |
| 202 // the content. | 202 // the content. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 226 // being created. | 226 // being created. |
| 227 AttachWebActivityHelpers(evicted_web_contents_.get()); | 227 AttachWebActivityHelpers(evicted_web_contents_.get()); |
| 228 | 228 |
| 229 SwapWebContents(evicted_web_contents_.Pass()); | 229 SwapWebContents(evicted_web_contents_.Pass()); |
| 230 } | 230 } |
| 231 | 231 |
| 232 // Check if the content got evicted. | 232 // Check if the content got evicted. |
| 233 const bool IsContentEvicted() { return !!evicted_web_contents_.get(); } | 233 const bool IsContentEvicted() { return !!evicted_web_contents_.get(); } |
| 234 | 234 |
| 235 // content::WebContentsDelegate: | 235 // content::WebContentsDelegate: |
| 236 virtual content::WebContents* OpenURLFromTab( | 236 content::WebContents* OpenURLFromTab( |
| 237 content::WebContents* source, | 237 content::WebContents* source, |
| 238 const content::OpenURLParams& params) override { | 238 const content::OpenURLParams& params) override { |
| 239 switch(params.disposition) { | 239 switch(params.disposition) { |
| 240 case CURRENT_TAB: { | 240 case CURRENT_TAB: { |
| 241 DCHECK(source == web_contents()); | 241 DCHECK(source == web_contents()); |
| 242 content::NavigationController::LoadURLParams load_url_params( | 242 content::NavigationController::LoadURLParams load_url_params( |
| 243 params.url); | 243 params.url); |
| 244 load_url_params.referrer = params.referrer; | 244 load_url_params.referrer = params.referrer; |
| 245 load_url_params.frame_tree_node_id = params.frame_tree_node_id; | 245 load_url_params.frame_tree_node_id = params.frame_tree_node_id; |
| 246 load_url_params.transition_type = params.transition; | 246 load_url_params.transition_type = params.transition; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 262 Activity::Show(activity); | 262 Activity::Show(activity); |
| 263 break; | 263 break; |
| 264 } | 264 } |
| 265 default: | 265 default: |
| 266 break; | 266 break; |
| 267 } | 267 } |
| 268 // nullptr is returned if the URL wasn't opened immediately. | 268 // nullptr is returned if the URL wasn't opened immediately. |
| 269 return nullptr; | 269 return nullptr; |
| 270 } | 270 } |
| 271 | 271 |
| 272 virtual bool CanOverscrollContent() const override { | 272 bool CanOverscrollContent() const override { |
| 273 const std::string value = CommandLine::ForCurrentProcess()-> | 273 const std::string value = CommandLine::ForCurrentProcess()-> |
| 274 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation); | 274 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation); |
| 275 return value != "0"; | 275 return value != "0"; |
| 276 } | 276 } |
| 277 | 277 |
| 278 virtual void OverscrollUpdate(float delta_y) override { | 278 void OverscrollUpdate(float delta_y) override { |
| 279 overscroll_y_ = delta_y; | 279 overscroll_y_ = delta_y; |
| 280 if (overscroll_y_ > kDistanceShowReloadMessage) { | 280 if (overscroll_y_ > kDistanceShowReloadMessage) { |
| 281 if (!reload_message_) | 281 if (!reload_message_) |
| 282 CreateReloadMessage(); | 282 CreateReloadMessage(); |
| 283 reload_message_->Show(); | 283 reload_message_->Show(); |
| 284 float opacity = 1.0f; | 284 float opacity = 1.0f; |
| 285 if (overscroll_y_ < kDistanceReload) { | 285 if (overscroll_y_ < kDistanceReload) { |
| 286 opacity = (overscroll_y_ - kDistanceShowReloadMessage) / | 286 opacity = (overscroll_y_ - kDistanceShowReloadMessage) / |
| 287 (kDistanceReload - kDistanceShowReloadMessage); | 287 (kDistanceReload - kDistanceShowReloadMessage); |
| 288 } | 288 } |
| 289 reload_message_->GetLayer()->SetOpacity(opacity); | 289 reload_message_->GetLayer()->SetOpacity(opacity); |
| 290 } else if (reload_message_) { | 290 } else if (reload_message_) { |
| 291 reload_message_->Hide(); | 291 reload_message_->Hide(); |
| 292 } | 292 } |
| 293 } | 293 } |
| 294 | 294 |
| 295 virtual void OverscrollComplete() override { | 295 void OverscrollComplete() override { |
| 296 if (overscroll_y_ >= kDistanceReload) | 296 if (overscroll_y_ >= kDistanceReload) |
| 297 GetWebContents()->GetController().Reload(false); | 297 GetWebContents()->GetController().Reload(false); |
| 298 if (reload_message_) | 298 if (reload_message_) |
| 299 reload_message_->Hide(); | 299 reload_message_->Hide(); |
| 300 overscroll_y_ = 0; | 300 overscroll_y_ = 0; |
| 301 } | 301 } |
| 302 | 302 |
| 303 virtual void AddNewContents(content::WebContents* source, | 303 void AddNewContents(content::WebContents* source, |
| 304 content::WebContents* new_contents, | 304 content::WebContents* new_contents, |
| 305 WindowOpenDisposition disposition, | 305 WindowOpenDisposition disposition, |
| 306 const gfx::Rect& initial_pos, | 306 const gfx::Rect& initial_pos, |
| 307 bool user_gesture, | 307 bool user_gesture, |
| 308 bool* was_blocked) override { | 308 bool* was_blocked) override { |
| 309 Activity* activity = | 309 Activity* activity = |
| 310 ActivityFactory::Get()->CreateWebActivity(new_contents); | 310 ActivityFactory::Get()->CreateWebActivity(new_contents); |
| 311 Activity::Show(activity); | 311 Activity::Show(activity); |
| 312 } | 312 } |
| 313 | 313 |
| 314 virtual bool PreHandleKeyboardEvent( | 314 bool PreHandleKeyboardEvent(content::WebContents* source, |
| 315 content::WebContents* source, | 315 const content::NativeWebKeyboardEvent& event, |
| 316 const content::NativeWebKeyboardEvent& event, | 316 bool* is_keyboard_shortcut) override { |
| 317 bool* is_keyboard_shortcut) override { | |
| 318 return controller_->PreHandleKeyboardEvent( | 317 return controller_->PreHandleKeyboardEvent( |
| 319 source, event, is_keyboard_shortcut); | 318 source, event, is_keyboard_shortcut); |
| 320 } | 319 } |
| 321 | 320 |
| 322 virtual void HandleKeyboardEvent( | 321 void HandleKeyboardEvent( |
| 323 content::WebContents* source, | 322 content::WebContents* source, |
| 324 const content::NativeWebKeyboardEvent& event) override { | 323 const content::NativeWebKeyboardEvent& event) override { |
| 325 controller_->HandleKeyboardEvent(source, event); | 324 controller_->HandleKeyboardEvent(source, event); |
| 326 } | 325 } |
| 327 | 326 |
| 328 virtual void ToggleFullscreenModeForTab(content::WebContents* web_contents, | 327 void ToggleFullscreenModeForTab(content::WebContents* web_contents, |
| 329 bool enter_fullscreen) override { | 328 bool enter_fullscreen) override { |
| 330 fullscreen_ = enter_fullscreen; | 329 fullscreen_ = enter_fullscreen; |
| 331 GetWidget()->SetFullscreen(fullscreen_); | 330 GetWidget()->SetFullscreen(fullscreen_); |
| 332 } | 331 } |
| 333 | 332 |
| 334 virtual bool IsFullscreenForTabOrPending( | 333 bool IsFullscreenForTabOrPending( |
| 335 const content::WebContents* web_contents) const override { | 334 const content::WebContents* web_contents) const override { |
| 336 return fullscreen_; | 335 return fullscreen_; |
| 337 } | 336 } |
| 338 | 337 |
| 339 virtual void LoadingStateChanged(content::WebContents* source, | 338 void LoadingStateChanged(content::WebContents* source, |
| 340 bool to_different_document) override { | 339 bool to_different_document) override { |
| 341 bool has_stopped = source == nullptr || !source->IsLoading(); | 340 bool has_stopped = source == nullptr || !source->IsLoading(); |
| 342 LoadProgressChanged(source, has_stopped ? 1 : 0); | 341 LoadProgressChanged(source, has_stopped ? 1 : 0); |
| 343 } | 342 } |
| 344 | 343 |
| 345 virtual void LoadProgressChanged(content::WebContents* source, | 344 void LoadProgressChanged(content::WebContents* source, |
| 346 double progress) override { | 345 double progress) override { |
| 347 if (!progress) | 346 if (!progress) |
| 348 return; | 347 return; |
| 349 | 348 |
| 350 if (!progress_bar_) { | 349 if (!progress_bar_) { |
| 351 CreateProgressBar(); | 350 CreateProgressBar(); |
| 352 source->GetNativeView()->layer()->Add(progress_bar_.get()); | 351 source->GetNativeView()->layer()->Add(progress_bar_.get()); |
| 353 } | 352 } |
| 354 progress_bar_->SetBounds(gfx::Rect( | 353 progress_bar_->SetBounds(gfx::Rect( |
| 355 0, 0, progress * progress_bar_->parent()->bounds().width(), 3)); | 354 0, 0, progress * progress_bar_->parent()->bounds().width(), 3)); |
| 356 if (progress < 1) | 355 if (progress < 1) |
| 357 return; | 356 return; |
| 358 | 357 |
| 359 ui::ScopedLayerAnimationSettings settings(progress_bar_->GetAnimator()); | 358 ui::ScopedLayerAnimationSettings settings(progress_bar_->GetAnimator()); |
| 360 settings.SetTweenType(gfx::Tween::EASE_IN); | 359 settings.SetTweenType(gfx::Tween::EASE_IN); |
| 361 ui::Layer* layer = progress_bar_.get(); | 360 ui::Layer* layer = progress_bar_.get(); |
| 362 settings.AddObserver(new ui::ClosureAnimationObserver( | 361 settings.AddObserver(new ui::ClosureAnimationObserver( |
| 363 base::Bind(&base::DeletePointer<ui::Layer>, progress_bar_.release()))); | 362 base::Bind(&base::DeletePointer<ui::Layer>, progress_bar_.release()))); |
| 364 layer->SetOpacity(0.f); | 363 layer->SetOpacity(0.f); |
| 365 } | 364 } |
| 366 | 365 |
| 367 virtual content::JavaScriptDialogManager* GetJavaScriptDialogManager() | 366 content::JavaScriptDialogManager* GetJavaScriptDialogManager() override { |
| 368 override { | |
| 369 NOTIMPLEMENTED(); | 367 NOTIMPLEMENTED(); |
| 370 return nullptr; | 368 return nullptr; |
| 371 } | 369 } |
| 372 | 370 |
| 373 virtual content::ColorChooser* OpenColorChooser( | 371 content::ColorChooser* OpenColorChooser( |
| 374 content::WebContents* web_contents, | 372 content::WebContents* web_contents, |
| 375 SkColor color, | 373 SkColor color, |
| 376 const std::vector<content::ColorSuggestion>& suggestions) override { | 374 const std::vector<content::ColorSuggestion>& suggestions) override { |
| 377 return athena::OpenColorChooser(web_contents, color, suggestions); | 375 return athena::OpenColorChooser(web_contents, color, suggestions); |
| 378 } | 376 } |
| 379 | 377 |
| 380 // Called when a file selection is to be done. | 378 // Called when a file selection is to be done. |
| 381 virtual void RunFileChooser( | 379 void RunFileChooser(content::WebContents* web_contents, |
| 382 content::WebContents* web_contents, | 380 const content::FileChooserParams& params) override { |
| 383 const content::FileChooserParams& params) override { | |
| 384 return athena::OpenFileChooser(web_contents, params); | 381 return athena::OpenFileChooser(web_contents, params); |
| 385 } | 382 } |
| 386 | 383 |
| 387 virtual void CloseContents(content::WebContents* contents) override { | 384 void CloseContents(content::WebContents* contents) override { |
| 388 Activity::Delete(owner_activity_); | 385 Activity::Delete(owner_activity_); |
| 389 } | 386 } |
| 390 | 387 |
| 391 private: | 388 private: |
| 392 void CreateProgressBar() { | 389 void CreateProgressBar() { |
| 393 CHECK(!progress_bar_); | 390 CHECK(!progress_bar_); |
| 394 progress_bar_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); | 391 progress_bar_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); |
| 395 progress_bar_->SetColor(SkColorSetRGB(0x17, 0x59, 0xcd)); | 392 progress_bar_->SetColor(SkColorSetRGB(0x17, 0x59, 0xcd)); |
| 396 } | 393 } |
| 397 | 394 |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 if (content_proxy_.get()) | 644 if (content_proxy_.get()) |
| 648 content_proxy_.reset(nullptr); | 645 content_proxy_.reset(nullptr); |
| 649 } | 646 } |
| 650 | 647 |
| 651 void WebActivity::ShowContentProxy() { | 648 void WebActivity::ShowContentProxy() { |
| 652 if (!content_proxy_.get()) | 649 if (!content_proxy_.get()) |
| 653 content_proxy_.reset(new ContentProxy(web_view_)); | 650 content_proxy_.reset(new ContentProxy(web_view_)); |
| 654 } | 651 } |
| 655 | 652 |
| 656 } // namespace athena | 653 } // namespace athena |
| OLD | NEW |