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

Side by Side Diff: mash/browser/browser.cc

Issue 2057023002: Adds support for new-tab targeted loads initiated from the renderer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 6 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 | mash/webtest/webtest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "mash/browser/browser.h" 5 #include "mash/browser/browser.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 86
87 Tab* tab_; 87 Tab* tab_;
88 88
89 DISALLOW_COPY_AND_ASSIGN(Background); 89 DISALLOW_COPY_AND_ASSIGN(Background);
90 }; 90 };
91 91
92 Tab(std::unique_ptr<navigation::View> view, 92 Tab(std::unique_ptr<navigation::View> view,
93 views::ButtonListener* listener) 93 views::ButtonListener* listener)
94 : views::LabelButton(listener, base::ASCIIToUTF16("Blank")), 94 : views::LabelButton(listener, base::ASCIIToUTF16("Blank")),
95 view_(std::move(view)) { 95 view_(std::move(view)) {
96 view_->SetResizerSize(gfx::Size(16, 16));
97 view_->AddObserver(this); 96 view_->AddObserver(this);
98 set_background(new Background(this)); 97 set_background(new Background(this));
99 } 98 }
100 ~Tab() override { 99 ~Tab() override {
101 view_->RemoveObserver(this); 100 view_->RemoveObserver(this);
102 } 101 }
103 102
104 bool selected() const { return selected_; } 103 bool selected() const { return selected_; }
105 104
106 mus::Window* window() { return window_; } 105 mus::Window* window() { return window_; }
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 if (tab_index < selected_index_) 225 if (tab_index < selected_index_)
227 --selected_index_; 226 --selected_index_;
228 DCHECK(it != tabs_.end()); 227 DCHECK(it != tabs_.end());
229 tabs_.erase(it); 228 tabs_.erase(it);
230 RemoveObserver(tab); 229 RemoveObserver(tab);
231 tab_container_->RemoveChildView(tab); 230 tab_container_->RemoveChildView(tab);
232 if (tab->selected()) { 231 if (tab->selected()) {
233 int next_selected_index = selected_index_; 232 int next_selected_index = selected_index_;
234 if (selected_index_ == static_cast<int>(tabs_.size())) 233 if (selected_index_ == static_cast<int>(tabs_.size()))
235 --next_selected_index; 234 --next_selected_index;
236 SelectTab(tabs_[next_selected_index]); 235 if (next_selected_index >= 0)
236 SelectTab(tabs_[next_selected_index]);
237 } 237 }
238 Layout(); 238 Layout();
239 FOR_EACH_OBSERVER(TabStripObserver, observers_, OnTabRemoved(tab)); 239 FOR_EACH_OBSERVER(TabStripObserver, observers_, OnTabRemoved(tab));
240 delete tab; 240 delete tab;
241 } 241 }
242 242
243 bool empty() const { return tabs_.empty(); } 243 bool empty() const { return tabs_.empty(); }
244 244
245 void SelectTab(Tab* tab) { 245 void SelectTab(Tab* tab) {
246 auto it = std::find(tabs_.begin(), tabs_.end(), tab); 246 auto it = std::find(tabs_.begin(), tabs_.end(), tab);
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 if (GetWidget()) 714 if (GetWidget())
715 GetWidget()->UpdateWindowTitle(); 715 GetWidget()->UpdateWindowTitle();
716 } 716 }
717 717
718 // navigation::ViewDelegate: 718 // navigation::ViewDelegate:
719 void ViewCreated(navigation::View* source, 719 void ViewCreated(navigation::View* source,
720 std::unique_ptr<navigation::View> view, 720 std::unique_ptr<navigation::View> view,
721 bool is_popup, 721 bool is_popup,
722 const gfx::Rect& initial_rect, 722 const gfx::Rect& initial_rect,
723 bool user_gesture) override { 723 bool user_gesture) override {
724 if (is_popup) { 724 if (is_popup)
725 views::Widget* window = views::Widget::CreateWindowWithContextAndBounds( 725 CreateNewWindow(std::move(view), initial_rect, is_popup);
726 new UI(browser_, is_popup ? UI::Type::POPUP : UI::Type::WINDOW, 726 else
727 std::move(view)),
728 nullptr, initial_rect);
729 window->Show();
730 browser_->AddWindow(window);
731 } else {
732 tab_strip_->AddTab(std::move(view)); 727 tab_strip_->AddTab(std::move(view));
733 }
734 } 728 }
735 void Close(navigation::View* source) override { 729 void Close(navigation::View* source) override {
736 tab_strip_->CloseTabForView(source); 730 tab_strip_->CloseTabForView(source);
737 if (tab_strip_->empty()) 731 if (tab_strip_->empty())
738 GetWidget()->Close(); 732 GetWidget()->Close();
739 } 733 }
734 void OpenURL(navigation::View* source,
735 navigation::mojom::OpenURLParamsPtr params) override {
736 switch (params->disposition) {
737 case navigation::mojom::WindowOpenDisposition::CURRENT_TAB:
738 selected_view()->NavigateToURL(params->url);
739 break;
740 case navigation::mojom::WindowOpenDisposition::NEW_FOREGROUND_TAB:
741 tab_strip_->AddTab(browser_->CreateView());
742 tab_strip_->selected_tab()->view()->NavigateToURL(params->url);
743 break;
744 case navigation::mojom::WindowOpenDisposition::NEW_POPUP:
745 case navigation::mojom::WindowOpenDisposition::NEW_WINDOW: {
746 std::unique_ptr<navigation::View> view = browser_->CreateView();
747 view->NavigateToURL(params->url);
748 CreateNewWindow(
749 std::move(view), gfx::Rect(),
750 params->disposition ==
751 navigation::mojom::WindowOpenDisposition::NEW_POPUP);
752 break;
753 }
754 default:
755 break;
756 }
757 }
740 758
741 // navigation::ViewObserver: 759 // navigation::ViewObserver:
742 void LoadingStateChanged(navigation::View* view) override { 760 void LoadingStateChanged(navigation::View* view) override {
743 if (view->is_loading()) { 761 if (view->is_loading()) {
744 reload_button_->SetText(base::ASCIIToUTF16("Stop")); 762 reload_button_->SetText(base::ASCIIToUTF16("Stop"));
745 throbber_->Start(); 763 throbber_->Start();
746 } else { 764 } else {
747 reload_button_->SetText(base::ASCIIToUTF16("Reload")); 765 reload_button_->SetText(base::ASCIIToUTF16("Reload"));
748 throbber_->Stop(); 766 throbber_->Stop();
749 progress_bar_->SetProgress(0.f); 767 progress_bar_->SetProgress(0.f);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 } 801 }
784 802
785 navigation::View* selected_view() { 803 navigation::View* selected_view() {
786 return const_cast<navigation::View*>( 804 return const_cast<navigation::View*>(
787 static_cast<const UI*>(this)->selected_view()); 805 static_cast<const UI*>(this)->selected_view());
788 } 806 }
789 const navigation::View* selected_view() const { 807 const navigation::View* selected_view() const {
790 return tab_strip_->selected_tab()->view(); 808 return tab_strip_->selected_tab()->view();
791 } 809 }
792 810
811 void CreateNewWindow(std::unique_ptr<navigation::View> view,
812 const gfx::Rect& initial_bounds,
813 bool is_popup) {
814 gfx::Rect bounds = initial_bounds;
815 if (bounds.IsEmpty())
816 bounds = gfx::Rect(10, 10, 400, 300);
817 views::Widget* window = views::Widget::CreateWindowWithContextAndBounds(
818 new UI(browser_, is_popup ? UI::Type::POPUP : UI::Type::WINDOW,
819 std::move(view)),
820 nullptr, bounds);
821 window->Show();
822 browser_->AddWindow(window);
823 }
824
793 void ToggleDebugView() { 825 void ToggleDebugView() {
794 showing_debug_view_ = !showing_debug_view_; 826 showing_debug_view_ = !showing_debug_view_;
795 Layout(); 827 Layout();
796 } 828 }
797 829
798 Browser* browser_; 830 Browser* browser_;
799 831
800 Type type_; 832 Type type_;
801 833
802 TabStrip* tab_strip_; 834 TabStrip* tab_strip_;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 AddWindow(window); 901 AddWindow(window);
870 } 902 }
871 903
872 void Browser::Create(shell::Connection* connection, 904 void Browser::Create(shell::Connection* connection,
873 mojom::LaunchableRequest request) { 905 mojom::LaunchableRequest request) {
874 bindings_.AddBinding(this, std::move(request)); 906 bindings_.AddBinding(this, std::move(request));
875 } 907 }
876 908
877 } // namespace browser 909 } // namespace browser
878 } // namespace mash 910 } // namespace mash
OLDNEW
« no previous file with comments | « no previous file | mash/webtest/webtest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698