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

Side by Side Diff: athena/content/web_activity.cc

Issue 659113002: Fix window.close() in Athena (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Pass the activity object instead of finding from the activity manager. Created 6 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 29 matching lines...) Expand all
40 public: 40 public:
41 enum Command { 41 enum Command {
42 CMD_BACK, 42 CMD_BACK,
43 CMD_FORWARD, 43 CMD_FORWARD,
44 CMD_RELOAD, 44 CMD_RELOAD,
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(views::WebView* web_view) 50 explicit WebActivityController(WebActivity* owner_activity,
51 : web_view_(web_view), reserved_accelerator_enabled_(true) {} 51 views::WebView* web_view)
52 : owner_activity_(owner_activity),
53 web_view_(web_view),
54 reserved_accelerator_enabled_(true) {}
52 virtual ~WebActivityController() {} 55 virtual ~WebActivityController() {}
53 56
54 // Installs accelerators for web activity. 57 // Installs accelerators for web activity.
55 void InstallAccelerators() { 58 void InstallAccelerators() {
56 accelerator_manager_ = AcceleratorManager::CreateForFocusManager( 59 accelerator_manager_ = AcceleratorManager::CreateForFocusManager(
57 web_view_->GetFocusManager()).Pass(); 60 web_view_->GetFocusManager()).Pass();
58 const AcceleratorData accelerator_data[] = { 61 const AcceleratorData accelerator_data[] = {
59 {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,
60 AF_NONE}, 63 AF_NONE},
61 {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,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 case CMD_RELOAD_IGNORE_CACHE: 132 case CMD_RELOAD_IGNORE_CACHE:
130 web_view_->GetWebContents()->GetController().ReloadIgnoringCache(false); 133 web_view_->GetWebContents()->GetController().ReloadIgnoringCache(false);
131 return true; 134 return true;
132 case CMD_BACK: 135 case CMD_BACK:
133 web_view_->GetWebContents()->GetController().GoBack(); 136 web_view_->GetWebContents()->GetController().GoBack();
134 return true; 137 return true;
135 case CMD_FORWARD: 138 case CMD_FORWARD:
136 web_view_->GetWebContents()->GetController().GoForward(); 139 web_view_->GetWebContents()->GetController().GoForward();
137 return true; 140 return true;
138 case CMD_CLOSE: 141 case CMD_CLOSE:
139 web_view_->GetWidget()->Close(); 142 Activity::Delete(owner_activity_);
140 return true; 143 return true;
141 case CMD_STOP: 144 case CMD_STOP:
142 web_view_->GetWebContents()->Stop(); 145 web_view_->GetWebContents()->Stop();
143 return true; 146 return true;
144 } 147 }
145 return false; 148 return false;
146 } 149 }
147 150
151 Activity* const owner_activity_;
148 views::WebView* web_view_; 152 views::WebView* web_view_;
149 bool reserved_accelerator_enabled_; 153 bool reserved_accelerator_enabled_;
150 scoped_ptr<AcceleratorManager> accelerator_manager_; 154 scoped_ptr<AcceleratorManager> accelerator_manager_;
151 views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_; 155 views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_;
152 156
153 DISALLOW_COPY_AND_ASSIGN(WebActivityController); 157 DISALLOW_COPY_AND_ASSIGN(WebActivityController);
154 }; 158 };
155 159
156 const SkColor kDefaultTitleColor = SkColorSetRGB(0xf2, 0xf2, 0xf2); 160 const SkColor kDefaultTitleColor = SkColorSetRGB(0xf2, 0xf2, 0xf2);
157 const int kIconSize = 32; 161 const int kIconSize = 32;
158 const float kDistanceShowReloadMessage = 100; 162 const float kDistanceShowReloadMessage = 100;
159 const float kDistanceReload = 150; 163 const float kDistanceReload = 150;
160 164
161 } // namespace 165 } // namespace
162 166
163 // A web view for athena's web activity. Note that AthenaWebView will create its 167 // A web view for athena's web activity. Note that AthenaWebView will create its
164 // own content so that it can eject and reload it. 168 // own content so that it can eject and reload it.
165 class AthenaWebView : public views::WebView { 169 class AthenaWebView : public views::WebView {
166 public: 170 public:
167 explicit AthenaWebView(content::BrowserContext* context) 171 explicit AthenaWebView(content::BrowserContext* context,
172 WebActivity* owner_activity)
168 : views::WebView(context), 173 : views::WebView(context),
169 controller_(new WebActivityController(this)), 174 controller_(new WebActivityController(owner_activity, this)),
175 owner_activity_(owner_activity),
170 fullscreen_(false), 176 fullscreen_(false),
171 overscroll_y_(0) { 177 overscroll_y_(0) {
172 SetEmbedFullscreenWidgetMode(true); 178 SetEmbedFullscreenWidgetMode(true);
173 // TODO(skuhne): Add content observer to detect renderer crash and set 179 // TODO(skuhne): Add content observer to detect renderer crash and set
174 // content status to unloaded if that happens. 180 // content status to unloaded if that happens.
175 } 181 }
176 182
177 AthenaWebView(content::WebContents* web_contents) 183 AthenaWebView(content::WebContents* web_contents,
184 WebActivity* owner_activity)
178 : views::WebView(web_contents->GetBrowserContext()), 185 : views::WebView(web_contents->GetBrowserContext()),
179 controller_(new WebActivityController(this)) { 186 controller_(new WebActivityController(owner_activity, this)),
187 owner_activity_(owner_activity) {
180 scoped_ptr<content::WebContents> old_contents( 188 scoped_ptr<content::WebContents> old_contents(
181 SwapWebContents(scoped_ptr<content::WebContents>(web_contents))); 189 SwapWebContents(scoped_ptr<content::WebContents>(web_contents)));
182 } 190 }
183 191
184 virtual ~AthenaWebView() {} 192 virtual ~AthenaWebView() {}
185 193
186 void InstallAccelerators() { controller_->InstallAccelerators(); } 194 void InstallAccelerators() { controller_->InstallAccelerators(); }
187 195
188 void EvictContent() { 196 void EvictContent() {
189 scoped_ptr<content::WebContents> old_contents(SwapWebContents( 197 scoped_ptr<content::WebContents> old_contents(SwapWebContents(
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 return athena::OpenColorChooser(web_contents, color, suggestions); 371 return athena::OpenColorChooser(web_contents, color, suggestions);
364 } 372 }
365 373
366 // Called when a file selection is to be done. 374 // Called when a file selection is to be done.
367 virtual void RunFileChooser( 375 virtual void RunFileChooser(
368 content::WebContents* web_contents, 376 content::WebContents* web_contents,
369 const content::FileChooserParams& params) override { 377 const content::FileChooserParams& params) override {
370 return athena::OpenFileChooser(web_contents, params); 378 return athena::OpenFileChooser(web_contents, params);
371 } 379 }
372 380
381 virtual void CloseContents(content::WebContents* contents) override {
382 Activity::Delete(owner_activity_);
383 }
384
373 private: 385 private:
374 void CreateProgressBar() { 386 void CreateProgressBar() {
375 CHECK(!progress_bar_); 387 CHECK(!progress_bar_);
376 progress_bar_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); 388 progress_bar_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR));
377 progress_bar_->SetColor(SkColorSetRGB(0x17, 0x59, 0xcd)); 389 progress_bar_->SetColor(SkColorSetRGB(0x17, 0x59, 0xcd));
378 } 390 }
379 391
380 void CreateReloadMessage() { 392 void CreateReloadMessage() {
381 CHECK(!reload_message_); 393 CHECK(!reload_message_);
382 reload_message_.reset(new views::Widget); 394 reload_message_.reset(new views::Widget);
383 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); 395 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL);
384 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 396 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
385 params.parent = GetWidget()->GetNativeView(); 397 params.parent = GetWidget()->GetNativeView();
386 reload_message_->Init(params); 398 reload_message_->Init(params);
387 399
388 views::Label* label = new views::Label( 400 views::Label* label = new views::Label(
389 l10n_util::GetStringUTF16(IDS_ATHENA_PULL_TO_RELOAD_MESSAGE)); 401 l10n_util::GetStringUTF16(IDS_ATHENA_PULL_TO_RELOAD_MESSAGE));
390 label->SetBackgroundColor(SK_ColorGRAY); 402 label->SetBackgroundColor(SK_ColorGRAY);
391 label->set_background( 403 label->set_background(
392 views::Background::CreateSolidBackground(SK_ColorGRAY)); 404 views::Background::CreateSolidBackground(SK_ColorGRAY));
393 405
394 reload_message_->SetContentsView(label); 406 reload_message_->SetContentsView(label);
395 reload_message_->SetBounds(ConvertRectToWidget( 407 reload_message_->SetBounds(ConvertRectToWidget(
396 gfx::Rect(0, 0, width(), label->GetPreferredSize().height()))); 408 gfx::Rect(0, 0, width(), label->GetPreferredSize().height())));
397 } 409 }
398 410
399 scoped_ptr<WebActivityController> controller_; 411 scoped_ptr<WebActivityController> controller_;
400 412
413 Activity* const owner_activity_;
414
401 // If the activity got evicted, this is the web content which holds the known 415 // If the activity got evicted, this is the web content which holds the known
402 // state of the content before eviction. 416 // state of the content before eviction.
403 scoped_ptr<content::WebContents> evicted_web_contents_; 417 scoped_ptr<content::WebContents> evicted_web_contents_;
404 418
405 scoped_ptr<ui::Layer> progress_bar_; 419 scoped_ptr<ui::Layer> progress_bar_;
406 420
407 scoped_ptr<views::Widget> reload_message_; 421 scoped_ptr<views::Widget> reload_message_;
408 422
409 // TODO(oshima): Find out if we should support window fullscreen. 423 // TODO(oshima): Find out if we should support window fullscreen.
410 // It may still useful when a user is in split mode. 424 // It may still useful when a user is in split mode.
411 bool fullscreen_; 425 bool fullscreen_;
412 426
413 // The distance that the user has overscrolled vertically. 427 // The distance that the user has overscrolled vertically.
414 float overscroll_y_; 428 float overscroll_y_;
415 429
416 DISALLOW_COPY_AND_ASSIGN(AthenaWebView); 430 DISALLOW_COPY_AND_ASSIGN(AthenaWebView);
417 }; 431 };
418 432
419 WebActivity::WebActivity(content::BrowserContext* browser_context, 433 WebActivity::WebActivity(content::BrowserContext* browser_context,
420 const base::string16& title, 434 const base::string16& title,
421 const GURL& url) 435 const GURL& url)
422 : browser_context_(browser_context), 436 : browser_context_(browser_context),
423 web_view_(new AthenaWebView(browser_context)), 437 web_view_(new AthenaWebView(browser_context, this)),
424 title_(title), 438 title_(title),
425 title_color_(kDefaultTitleColor), 439 title_color_(kDefaultTitleColor),
426 current_state_(ACTIVITY_UNLOADED), 440 current_state_(ACTIVITY_UNLOADED),
427 weak_ptr_factory_(this) { 441 weak_ptr_factory_(this) {
428 // Order is important. The web activity helpers must be attached prior to the 442 // Order is important. The web activity helpers must be attached prior to the
429 // RenderView being created. 443 // RenderView being created.
430 SetCurrentState(ACTIVITY_INVISIBLE); 444 SetCurrentState(ACTIVITY_INVISIBLE);
431 web_view_->LoadInitialURL(url); 445 web_view_->LoadInitialURL(url);
432 } 446 }
433 447
434 WebActivity::WebActivity(content::WebContents* contents) 448 WebActivity::WebActivity(content::WebContents* contents)
435 : browser_context_(contents->GetBrowserContext()), 449 : browser_context_(contents->GetBrowserContext()),
436 web_view_(new AthenaWebView(contents)), 450 web_view_(new AthenaWebView(contents, this)),
437 title_color_(kDefaultTitleColor), 451 title_color_(kDefaultTitleColor),
438 current_state_(ACTIVITY_UNLOADED), 452 current_state_(ACTIVITY_UNLOADED),
439 weak_ptr_factory_(this) { 453 weak_ptr_factory_(this) {
440 // If the activity was created as a result of 454 // If the activity was created as a result of
441 // WebContentsDelegate::AddNewContents(), web activity helpers may not be 455 // WebContentsDelegate::AddNewContents(), web activity helpers may not be
442 // created prior to the RenderView being created. Desktop Chrome has a 456 // created prior to the RenderView being created. Desktop Chrome has a
443 // similar problem. 457 // similar problem.
444 SetCurrentState(ACTIVITY_INVISIBLE); 458 SetCurrentState(ACTIVITY_INVISIBLE);
445 } 459 }
446 460
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 if (content_proxy_.get()) 641 if (content_proxy_.get())
628 content_proxy_.reset(NULL); 642 content_proxy_.reset(NULL);
629 } 643 }
630 644
631 void WebActivity::ShowContentProxy() { 645 void WebActivity::ShowContentProxy() {
632 if (!content_proxy_.get()) 646 if (!content_proxy_.get())
633 content_proxy_.reset(new ContentProxy(web_view_)); 647 content_proxy_.reset(new ContentProxy(web_view_));
634 } 648 }
635 649
636 } // namespace athena 650 } // namespace athena
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698