| 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/public/dialogs.h" | 10 #include "athena/content/public/dialogs.h" |
| 11 #include "athena/input/public/accelerator_manager.h" | 11 #include "athena/input/public/accelerator_manager.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "components/favicon_base/select_favicon_frames.h" | 15 #include "components/favicon_base/select_favicon_frames.h" |
| 16 #include "content/public/browser/native_web_keyboard_event.h" | 16 #include "content/public/browser/native_web_keyboard_event.h" |
| 17 #include "content/public/browser/navigation_controller.h" | 17 #include "content/public/browser/navigation_controller.h" |
| 18 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 19 #include "content/public/browser/web_contents_delegate.h" | 19 #include "content/public/browser/web_contents_delegate.h" |
| 20 #include "content/public/common/content_switches.h" | 20 #include "content/public/common/content_switches.h" |
| 21 #include "content/public/common/favicon_url.h" | 21 #include "content/public/common/favicon_url.h" |
| 22 #include "ui/aura/window.h" | 22 #include "ui/aura/window.h" |
| 23 #include "ui/compositor/closure_animation_observer.h" | 23 #include "ui/compositor/closure_animation_observer.h" |
| 24 #include "ui/compositor/scoped_layer_animation_settings.h" | 24 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 25 #include "ui/views/background.h" |
| 26 #include "ui/views/controls/label.h" |
| 25 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h" | 27 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h" |
| 26 #include "ui/views/controls/webview/webview.h" | 28 #include "ui/views/controls/webview/webview.h" |
| 27 #include "ui/views/focus/focus_manager.h" | 29 #include "ui/views/focus/focus_manager.h" |
| 28 #include "ui/views/widget/widget.h" | 30 #include "ui/views/widget/widget.h" |
| 29 | 31 |
| 30 namespace athena { | 32 namespace athena { |
| 31 namespace { | 33 namespace { |
| 32 | 34 |
| 33 class WebActivityController : public AcceleratorHandler { | 35 class WebActivityController : public AcceleratorHandler { |
| 34 public: | 36 public: |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 bool reserved_accelerator_enabled_; | 145 bool reserved_accelerator_enabled_; |
| 144 scoped_ptr<AcceleratorManager> accelerator_manager_; | 146 scoped_ptr<AcceleratorManager> accelerator_manager_; |
| 145 views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_; | 147 views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_; |
| 146 | 148 |
| 147 DISALLOW_COPY_AND_ASSIGN(WebActivityController); | 149 DISALLOW_COPY_AND_ASSIGN(WebActivityController); |
| 148 }; | 150 }; |
| 149 | 151 |
| 150 const SkColor kDefaultTitleColor = SkColorSetRGB(0xf2, 0xf2, 0xf2); | 152 const SkColor kDefaultTitleColor = SkColorSetRGB(0xf2, 0xf2, 0xf2); |
| 151 const SkColor kDefaultUnavailableColor = SkColorSetRGB(0xbb, 0x77, 0x77); | 153 const SkColor kDefaultUnavailableColor = SkColorSetRGB(0xbb, 0x77, 0x77); |
| 152 const int kIconSize = 32; | 154 const int kIconSize = 32; |
| 155 const int kDistanceShowReloadMessage = 100; |
| 156 const int kDistanceReload = 150; |
| 153 | 157 |
| 154 } // namespace | 158 } // namespace |
| 155 | 159 |
| 156 // A web view for athena's web activity. Note that AthenaWebView will create its | 160 // A web view for athena's web activity. Note that AthenaWebView will create its |
| 157 // own content so that it can eject and reload it. | 161 // own content so that it can eject and reload it. |
| 158 class AthenaWebView : public views::WebView { | 162 class AthenaWebView : public views::WebView { |
| 159 public: | 163 public: |
| 160 AthenaWebView(content::BrowserContext* context) | 164 AthenaWebView(content::BrowserContext* context) |
| 161 : views::WebView(context), controller_(new WebActivityController(this)), | 165 : views::WebView(context), controller_(new WebActivityController(this)), |
| 162 fullscreen_(false) { | 166 fullscreen_(false), |
| 167 overscroll_y_(0) { |
| 163 SetEmbedFullscreenWidgetMode(true); | 168 SetEmbedFullscreenWidgetMode(true); |
| 164 // TODO(skuhne): Add content observer to detect renderer crash and set | 169 // TODO(skuhne): Add content observer to detect renderer crash and set |
| 165 // content status to unloaded if that happens. | 170 // content status to unloaded if that happens. |
| 166 } | 171 } |
| 167 | 172 |
| 168 AthenaWebView(content::WebContents* web_contents) | 173 AthenaWebView(content::WebContents* web_contents) |
| 169 : views::WebView(web_contents->GetBrowserContext()), | 174 : views::WebView(web_contents->GetBrowserContext()), |
| 170 controller_(new WebActivityController(this)) { | 175 controller_(new WebActivityController(this)) { |
| 171 scoped_ptr<content::WebContents> old_contents( | 176 scoped_ptr<content::WebContents> old_contents( |
| 172 SwapWebContents(scoped_ptr<content::WebContents>(web_contents))); | 177 SwapWebContents(scoped_ptr<content::WebContents>(web_contents))); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 // NULL is returned if the URL wasn't opened immediately. | 246 // NULL is returned if the URL wasn't opened immediately. |
| 242 return NULL; | 247 return NULL; |
| 243 } | 248 } |
| 244 | 249 |
| 245 virtual bool CanOverscrollContent() const OVERRIDE { | 250 virtual bool CanOverscrollContent() const OVERRIDE { |
| 246 const std::string value = CommandLine::ForCurrentProcess()-> | 251 const std::string value = CommandLine::ForCurrentProcess()-> |
| 247 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation); | 252 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation); |
| 248 return value != "0"; | 253 return value != "0"; |
| 249 } | 254 } |
| 250 | 255 |
| 256 virtual void OverscrollUpdate(int delta_y) OVERRIDE { |
| 257 overscroll_y_ = delta_y; |
| 258 if (overscroll_y_ > kDistanceShowReloadMessage) { |
| 259 if (!reload_message_) |
| 260 CreateReloadMessage(); |
| 261 reload_message_->Show(); |
| 262 float opacity = 1.0f; |
| 263 if (overscroll_y_ < kDistanceReload) { |
| 264 opacity = |
| 265 (overscroll_y_ - kDistanceShowReloadMessage) / |
| 266 static_cast<float>(kDistanceReload - kDistanceShowReloadMessage); |
| 267 } |
| 268 reload_message_->GetLayer()->SetOpacity(opacity); |
| 269 } else if (reload_message_) { |
| 270 reload_message_->Hide(); |
| 271 } |
| 272 } |
| 273 |
| 274 virtual void OverscrollComplete() OVERRIDE { |
| 275 if (overscroll_y_ >= kDistanceReload) |
| 276 GetWebContents()->GetController().Reload(false); |
| 277 if (reload_message_) |
| 278 reload_message_->Hide(); |
| 279 overscroll_y_ = 0; |
| 280 } |
| 281 |
| 251 virtual void AddNewContents(content::WebContents* source, | 282 virtual void AddNewContents(content::WebContents* source, |
| 252 content::WebContents* new_contents, | 283 content::WebContents* new_contents, |
| 253 WindowOpenDisposition disposition, | 284 WindowOpenDisposition disposition, |
| 254 const gfx::Rect& initial_pos, | 285 const gfx::Rect& initial_pos, |
| 255 bool user_gesture, | 286 bool user_gesture, |
| 256 bool* was_blocked) OVERRIDE { | 287 bool* was_blocked) OVERRIDE { |
| 257 ActivityManager::Get()->AddActivity( | 288 ActivityManager::Get()->AddActivity( |
| 258 new WebActivity(new AthenaWebView(new_contents))); | 289 new WebActivity(new AthenaWebView(new_contents))); |
| 259 } | 290 } |
| 260 | 291 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 return athena::OpenFileChooser(web_contents, params); | 356 return athena::OpenFileChooser(web_contents, params); |
| 326 } | 357 } |
| 327 | 358 |
| 328 private: | 359 private: |
| 329 void CreateProgressBar() { | 360 void CreateProgressBar() { |
| 330 CHECK(!progress_bar_); | 361 CHECK(!progress_bar_); |
| 331 progress_bar_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); | 362 progress_bar_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); |
| 332 progress_bar_->SetColor(SkColorSetRGB(0x17, 0x59, 0xcd)); | 363 progress_bar_->SetColor(SkColorSetRGB(0x17, 0x59, 0xcd)); |
| 333 } | 364 } |
| 334 | 365 |
| 366 void CreateReloadMessage() { |
| 367 CHECK(!reload_message_); |
| 368 reload_message_.reset(new views::Widget); |
| 369 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); |
| 370 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 371 params.parent = GetWidget()->GetNativeView(); |
| 372 reload_message_->Init(params); |
| 373 |
| 374 views::Label* label = new views::Label(base::UTF8ToUTF16("Reload")); |
| 375 label->SetBackgroundColor(SK_ColorGRAY); |
| 376 label->set_background( |
| 377 views::Background::CreateSolidBackground(SK_ColorGRAY)); |
| 378 |
| 379 reload_message_->SetContentsView(label); |
| 380 reload_message_->SetBounds(ConvertRectToWidget( |
| 381 gfx::Rect(0, 0, width(), label->GetPreferredSize().height()))); |
| 382 } |
| 383 |
| 335 scoped_ptr<WebActivityController> controller_; | 384 scoped_ptr<WebActivityController> controller_; |
| 336 | 385 |
| 337 // If the activity got evicted, this is the web content which holds the known | 386 // If the activity got evicted, this is the web content which holds the known |
| 338 // state of the content before eviction. | 387 // state of the content before eviction. |
| 339 scoped_ptr<content::WebContents> evicted_web_contents_; | 388 scoped_ptr<content::WebContents> evicted_web_contents_; |
| 340 | 389 |
| 341 scoped_ptr<ui::Layer> progress_bar_; | 390 scoped_ptr<ui::Layer> progress_bar_; |
| 342 | 391 |
| 392 scoped_ptr<views::Widget> reload_message_; |
| 393 |
| 343 // TODO(oshima): Find out if we should support window fullscreen. | 394 // TODO(oshima): Find out if we should support window fullscreen. |
| 344 // It may still useful when a user is in split mode. | 395 // It may still useful when a user is in split mode. |
| 345 bool fullscreen_; | 396 bool fullscreen_; |
| 346 | 397 |
| 398 // The distance that the user has overscrolled vertically. |
| 399 int overscroll_y_; |
| 400 |
| 347 DISALLOW_COPY_AND_ASSIGN(AthenaWebView); | 401 DISALLOW_COPY_AND_ASSIGN(AthenaWebView); |
| 348 }; | 402 }; |
| 349 | 403 |
| 350 WebActivity::WebActivity(content::BrowserContext* browser_context, | 404 WebActivity::WebActivity(content::BrowserContext* browser_context, |
| 351 const base::string16& title, | 405 const base::string16& title, |
| 352 const GURL& url) | 406 const GURL& url) |
| 353 : browser_context_(browser_context), | 407 : browser_context_(browser_context), |
| 354 title_(title), | 408 title_(title), |
| 355 url_(url), | 409 url_(url), |
| 356 web_view_(NULL), | 410 web_view_(NULL), |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 | 632 |
| 579 void WebActivity::ReloadAndObserve() { | 633 void WebActivity::ReloadAndObserve() { |
| 580 if (web_view_->IsContentEvicted()) { | 634 if (web_view_->IsContentEvicted()) { |
| 581 DCHECK_EQ(ACTIVITY_UNLOADED, current_state_); | 635 DCHECK_EQ(ACTIVITY_UNLOADED, current_state_); |
| 582 web_view_->ReloadContent(); | 636 web_view_->ReloadContent(); |
| 583 } | 637 } |
| 584 Observe(web_view_->GetWebContents()); | 638 Observe(web_view_->GetWebContents()); |
| 585 } | 639 } |
| 586 | 640 |
| 587 } // namespace athena | 641 } // namespace athena |
| OLD | NEW |