Skip to content

Commit

Permalink
Add AppDelegate::ResizeWebContents
Browse files Browse the repository at this point in the history
To stop directly depending on apps/window_size_sizer from AppWindow.

BUG=403726
TBR=cbentzel@chromium.org for include/namespace fix in chrome/browser/prerender/prerender_contents.cc

Review URL: https://codereview.chromium.org/503233003

Cr-Commit-Position: refs/heads/master@{#292091}
  • Loading branch information
hashimoto authored and Commit bot committed Aug 27, 2014
1 parent 774dcda commit bf20fc6
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 48 deletions.
9 changes: 0 additions & 9 deletions apps/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ static_library("apps") {
"switches.h",
"ui/apps_client.cc",
"ui/apps_client.h",
"ui/web_contents_sizer.h",
]

configs += [ "//build/config/compiler:wexit_time_destructors" ]
Expand All @@ -63,14 +62,6 @@ static_library("apps") {
sources = []
}

# This needs to run after the extensions check above since we always want
# this file in the project.
if (is_mac) {
sources += [ "ui/web_contents_sizer.mm" ]
} else {
sources += [ "ui/web_contents_sizer.cc" ]
}

if (toolkit_views) {
sources += [
"ui/views/app_window_frame_view.cc",
Expand Down
3 changes: 1 addition & 2 deletions apps/app_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include "apps/app_window_registry.h"
#include "apps/ui/apps_client.h"
#include "apps/ui/web_contents_sizer.h"
#include "base/command_line.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
Expand Down Expand Up @@ -347,7 +346,7 @@ void AppWindow::Init(const GURL& url,
gfx::Insets frame_insets = native_app_window_->GetFrameInsets();
gfx::Rect initial_bounds = new_params.GetInitialWindowBounds(frame_insets);
initial_bounds.Inset(frame_insets);
apps::ResizeWebContents(web_contents, initial_bounds.size());
app_delegate_->ResizeWebContents(web_contents, initial_bounds.size());
}
}

Expand Down
12 changes: 0 additions & 12 deletions apps/apps.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,8 @@
'ui/views/app_window_frame_view.h',
'ui/views/native_app_window_views.cc',
'ui/views/native_app_window_views.h',
'ui/web_contents_sizer.h',
],
'conditions': [
['OS=="mac"', {
'sources': [
'ui/web_contents_sizer.mm',
],
}, { # OS!=mac
'sources': [
'ui/web_contents_sizer.cc',
],
}],
['chromeos==1',
{
'dependencies': [
Expand All @@ -89,8 +79,6 @@
],
'sources/': [
['exclude', '.*'],
['include', 'ui/web_contents_sizer\.cc$'],
['include', 'ui/web_contents_sizer\.mm$'],
],
}
],
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/prerender/prerender_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <functional>
#include <utility>

#include "apps/ui/web_contents_sizer.h"
#include "base/bind.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chrome_notification_types.h"
Expand All @@ -24,6 +23,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tab_helpers.h"
#include "chrome/browser/ui/web_contents_sizer.h"
#include "chrome/common/prerender_messages.h"
#include "chrome/common/render_messages.h"
#include "chrome/common/url_constants.h"
Expand Down Expand Up @@ -333,7 +333,7 @@ void PrerenderContents::StartPrerendering(
web_contents_delegate_.reset(new WebContentsDelegateImpl(this));
prerender_contents_.get()->SetDelegate(web_contents_delegate_.get());
// Set the size of the prerender WebContents.
apps::ResizeWebContents(prerender_contents_.get(), size_);
ResizeWebContents(prerender_contents_.get(), size_);

child_id_ = GetRenderViewHost()->GetProcess()->GetID();
route_id_ = GetRenderViewHost()->GetRoutingID();
Expand Down
6 changes: 6 additions & 0 deletions chrome/browser/ui/apps/chrome_app_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
#include "chrome/browser/ui/web_contents_sizer.h"
#include "chrome/common/extensions/chrome_extension_messages.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/notification_service.h"
Expand Down Expand Up @@ -176,6 +177,11 @@ void ChromeAppDelegate::InitWebContents(content::WebContents* web_contents) {
web_contents);
}

void ChromeAppDelegate::ResizeWebContents(content::WebContents* web_contents,
const gfx::Size& size) {
::ResizeWebContents(web_contents, size);
}

content::WebContents* ChromeAppDelegate::OpenURLFromTab(
content::BrowserContext* context,
content::WebContents* source,
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/ui/apps/chrome_app_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class ChromeAppDelegate : public extensions::AppDelegate,

// extensions::AppDelegate:
virtual void InitWebContents(content::WebContents* web_contents) OVERRIDE;
virtual void ResizeWebContents(content::WebContents* web_contents,
const gfx::Size& size) OVERRIDE;
virtual content::WebContents* OpenURLFromTab(
content::BrowserContext* context,
content::WebContents* source,
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/ui/browser_tabrestore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "chrome/browser/ui/browser_tabrestore.h"

#include "apps/ui/web_contents_sizer.h"
#include "chrome/browser/extensions/tab_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sessions/session_service.h"
Expand All @@ -13,6 +12,7 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/web_contents_sizer.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/session_storage_namespace.h"
Expand Down Expand Up @@ -127,7 +127,7 @@ content::WebContents* AddRestoredTab(
// yet and the bounds may not be available on all platforms.
if (size.IsEmpty())
size = browser->window()->GetRestoredBounds().size();
apps::ResizeWebContents(web_contents, size);
ResizeWebContents(web_contents, size);
web_contents->WasHidden();
}
SessionService* session_service =
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/ui/fullscreen/fullscreen_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "chrome/browser/ui/fullscreen/fullscreen_controller.h"

#include "apps/ui/web_contents_sizer.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/message_loop/message_loop.h"
Expand All @@ -19,6 +18,7 @@
#include "chrome/browser/ui/fullscreen/fullscreen_within_tab_helper.h"
#include "chrome/browser/ui/status_bubble.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/web_contents_sizer.h"
#include "chrome/common/chrome_switches.h"
#include "content/public/browser/navigation_details.h"
#include "content/public/browser/navigation_entry.h"
Expand Down Expand Up @@ -311,7 +311,7 @@ void FullscreenController::OnTabDetachedFromView(WebContents* old_contents) {
old_contents->GetFullscreenRenderWidgetHostView();
if (current_fs_view)
current_fs_view->SetSize(old_contents->GetPreferredSize());
apps::ResizeWebContents(old_contents, old_contents->GetPreferredSize());
ResizeWebContents(old_contents, old_contents->GetPreferredSize());
}

void FullscreenController::OnTabClosing(WebContents* web_contents) {
Expand Down
5 changes: 2 additions & 3 deletions chrome/browser/ui/tabs/tab_strip_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <map>
#include <string>

#include "apps/ui/web_contents_sizer.h"
#include "base/metrics/histogram.h"
#include "base/stl_util.h"
#include "chrome/app/chrome_command_ids.h"
Expand All @@ -20,6 +19,7 @@
#include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h"
#include "chrome/browser/ui/tabs/tab_strip_model_delegate.h"
#include "chrome/browser/ui/tabs/tab_strip_model_order_controller.h"
#include "chrome/browser/ui/web_contents_sizer.h"
#include "chrome/common/url_constants.h"
#include "components/web_modal/popup_manager.h"
#include "content/public/browser/render_process_host.h"
Expand Down Expand Up @@ -839,8 +839,7 @@ void TabStripModel::AddWebContents(WebContents* contents,
// new background tab.
if (WebContents* old_contents = GetActiveWebContents()) {
if ((add_types & ADD_ACTIVE) == 0) {
apps::ResizeWebContents(contents,
old_contents->GetContainerBounds().size());
ResizeWebContents(contents, old_contents->GetContainerBounds().size());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "apps/ui/web_contents_sizer.h"
#include "chrome/browser/ui/web_contents_sizer.h"

#include "content/public/browser/web_contents.h"

Expand All @@ -12,8 +12,6 @@
#include "content/public/browser/render_widget_host_view.h"
#endif

namespace apps {

void ResizeWebContents(content::WebContents* web_contents,
const gfx::Size& new_size) {
#if defined(USE_AURA)
Expand All @@ -25,5 +23,3 @@ void ResizeWebContents(content::WebContents* web_contents,
view->SetSize(new_size);
#endif
}

} // namespace apps
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef APPS_UI_WEB_CONTENTS_SIZER_H_
#define APPS_UI_WEB_CONTENTS_SIZER_H_
#ifndef CHROME_BROWSER_UI_WEB_CONTENTS_SIZER_H_
#define CHROME_BROWSER_UI_WEB_CONTENTS_SIZER_H_

namespace content {
class WebContents;
Expand All @@ -13,12 +13,9 @@ namespace gfx {
class Size;
}

namespace apps {
// A platform-agnostic function to resize a WebContents. The top-left corner of
// the WebContents does not move during the resizing.
void ResizeWebContents(content::WebContents* web_contents,
const gfx::Size& size);

} // namespace apps

#endif // APPS_UI_WEB_CONTENTS_SIZER_H_
#endif // CHROME_BROWSER_UI_WEB_CONTENTS_SIZER_H_
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "apps/ui/web_contents_sizer.h"
#include "chrome/browser/ui/web_contents_sizer.h"

#import <Cocoa/Cocoa.h>

#include "content/public/browser/web_contents.h"

namespace apps {

void ResizeWebContents(content::WebContents* web_contents,
const gfx::Size& new_size) {
NSView* view = web_contents->GetNativeView();
Expand All @@ -21,5 +19,3 @@ void ResizeWebContents(content::WebContents* web_contents,
NSMakeRect(new_x, new_y, new_size.width(), new_size.height());
[view setFrame:new_wcv_frame];
}

} // namespace apps
3 changes: 3 additions & 0 deletions chrome/chrome_browser_ui.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,7 @@
'browser/ui/uninstall_browser_prompt.h',
'browser/ui/validation_message_bubble.h',
'browser/ui/view_ids.h',
'browser/ui/web_contents_sizer.h',
'browser/ui/website_settings/permission_bubble_manager.cc',
'browser/ui/website_settings/permission_bubble_manager.h',
'browser/ui/website_settings/permission_bubble_request.h',
Expand Down Expand Up @@ -1327,8 +1328,10 @@
'chrome_browser_ui_mac_sources': [
'browser/ui/startup/session_crashed_bubble.cc',
'browser/ui/startup/autolaunch_prompt.cc',
'browser/ui/web_contents_sizer.mm',
],
'chrome_browser_ui_non_mac_sources': [
'browser/ui/web_contents_sizer.cc',
],
# Files used only on desktop systems (not iOS, Android, ChromeOS).
'chrome_browser_ui_desktop_sources': [
Expand Down
4 changes: 4 additions & 0 deletions extensions/browser/app_window/app_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class AppDelegate {
// General initialization.
virtual void InitWebContents(content::WebContents* web_contents) = 0;

// Resizes WebContents.
virtual void ResizeWebContents(content::WebContents* web_contents,
const gfx::Size& size) = 0;

// Link handling.
virtual content::WebContents* OpenURLFromTab(
content::BrowserContext* context,
Expand Down

0 comments on commit bf20fc6

Please sign in to comment.