#include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
#include "chrome/browser/extensions/suggest_permission_util.h"
#include "chrome/common/chrome_switches.h"
-#include "chrome/common/extensions/manifest_handlers/icons_handler.h"
#include "components/web_modal/web_contents_modal_dialog_manager.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/invalidate_type.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/resource_dispatcher_host.h"
#include "content/public/browser/web_contents.h"
-#include "content/public/browser/web_contents_view.h"
#include "content/public/common/media_stream_request.h"
+#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/extensions_browser_client.h"
#include "extensions/browser/process_manager.h"
#include "extensions/browser/view_type_utils.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_messages.h"
+#include "extensions/common/manifest_handlers/icons_handler.h"
+#include "grit/theme_resources.h"
#include "third_party/skia/include/core/SkRegion.h"
+#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/screen.h"
#if !defined(OS_MACOSX)
Delegate* delegate,
const extensions::Extension* extension)
: browser_context_(context),
- extension_(extension),
extension_id_(extension->id()),
window_type_(WINDOW_TYPE_DEFAULT),
delegate_(delegate),
native_app_window_.reset(delegate_->CreateNativeAppWindow(this, new_params));
- if (!new_params.hidden) {
- // Panels are not activated by default.
- Show(window_type_is_panel() || !new_params.focused ? SHOW_INACTIVE
- : SHOW_ACTIVE);
-#if defined(OS_CHROMEOS)
- } else {
+ if (new_params.hidden) {
// Although the window starts hidden by default, calling Hide() here
// notifies observers of the window being hidden.
Hide();
-#endif
+ } else {
+ // Panels are not activated by default.
+ Show(window_type_is_panel() || !new_params.focused ? SHOW_INACTIVE
+ : SHOW_ACTIVE);
}
if (new_params.state == ui::SHOW_STATE_FULLSCREEN)
// We want to show the window only when the content has been painted. For
// that to happen, we need to define a size for the content, otherwise the
// layout will happen in a 0x0 area.
- // Note: WebContents::GetView() is guaranteed to be non-null.
gfx::Insets frame_insets = native_app_window_->GetFrameInsets();
gfx::Rect initial_bounds = new_params.GetInitialWindowBounds(frame_insets);
initial_bounds.Inset(frame_insets);
content::WebContents* web_contents,
const content::MediaStreamRequest& request,
const content::MediaResponseCallback& callback) {
+ const extensions::Extension* extension = GetExtension();
+ if (!extension)
+ return;
+
delegate_->RequestMediaAccessPermission(
- web_contents, request, callback, extension());
+ web_contents, request, callback, extension);
}
WebContents* AppWindow::OpenURLFromTab(WebContents* source,
content::WebContents* source,
const content::NativeWebKeyboardEvent& event,
bool* is_keyboard_shortcut) {
+ const extensions::Extension* extension = GetExtension();
+ if (!extension)
+ return false;
+
// Here, we can handle a key event before the content gets it. When we are
// fullscreen and it is not forced, we want to allow the user to leave
// when ESC is pressed.
if (event.windowsKeyCode == ui::VKEY_ESCAPE &&
(fullscreen_types_ != FULLSCREEN_TYPE_NONE) &&
((fullscreen_types_ & FULLSCREEN_TYPE_FORCED) == 0) &&
- !extension_->HasAPIPermission(APIPermission::kOverrideEscFullscreen)) {
+ !extension->HasAPIPermission(APIPermission::kOverrideEscFullscreen)) {
Restore();
return true;
}
void AppWindow::RequestToLockMouse(WebContents* web_contents,
bool user_gesture,
bool last_unlocked_by_target) {
+ const extensions::Extension* extension = GetExtension();
+ if (!extension)
+ return;
+
bool has_permission = IsExtensionWithPermissionOrSuggestInConsole(
APIPermission::kPointerLock,
- extension_,
+ extension,
web_contents->GetRenderViewHost());
web_contents->GotResponseToLockMouseRequest(has_permission);
event.type == blink::WebGestureEvent::GesturePinchEnd;
}
-void AppWindow::DidFirstVisuallyNonEmptyPaint(int32 page_id) {
+void AppWindow::DidFirstVisuallyNonEmptyPaint() {
first_paint_complete_ = true;
if (show_on_first_paint_) {
DCHECK(delayed_show_type_ == SHOW_ACTIVE ||
return app_window_contents_->GetWebContents();
}
+const extensions::Extension* AppWindow::GetExtension() const {
+ return extensions::ExtensionRegistry::Get(browser_context_)
+ ->enabled_extensions()
+ .GetByID(extension_id_);
+}
+
NativeAppWindow* AppWindow::GetBaseWindow() { return native_app_window_.get(); }
gfx::NativeWindow AppWindow::GetNativeWindow() {
}
base::string16 AppWindow::GetTitle() const {
+ base::string16 title;
+ const extensions::Extension* extension = GetExtension();
+ if (!extension)
+ return title;
+
// WebContents::GetTitle() will return the page's URL if there's no <title>
// specified. However, we'd prefer to show the name of the extension in that
// case, so we directly inspect the NavigationEntry's title.
- base::string16 title;
if (!web_contents() || !web_contents()->GetController().GetActiveEntry() ||
web_contents()->GetController().GetActiveEntry()->GetTitle().empty()) {
- title = base::UTF8ToUTF16(extension()->name());
+ title = base::UTF8ToUTF16(extension->name());
} else {
title = web_contents()->GetTitle();
}
GetBaseWindow()->ShowInactive();
break;
}
-#if defined(OS_CHROMEOS)
AppWindowRegistry::Get(browser_context_)->AppWindowShown(this);
-#endif
}
void AppWindow::Hide() {
// show will not be delayed.
show_on_first_paint_ = false;
GetBaseWindow()->Hide();
-#if defined(OS_CHROMEOS)
AppWindowRegistry::Get(browser_context_)->AppWindowHidden(this);
-#endif
}
void AppWindow::SetAlwaysOnTop(bool always_on_top) {
properties->SetBoolean("maximized", native_app_window_->IsMaximized());
properties->SetBoolean("alwaysOnTop", IsAlwaysOnTop());
properties->SetBoolean("hasFrameColor", native_app_window_->HasFrameColor());
- properties->SetInteger("frameColor", native_app_window_->FrameColor());
+
+ // These properties are undocumented and are to enable testing. Alpha is
+ // removed to
+ // make the values easier to check.
+ SkColor transparent_white = ~SK_ColorBLACK;
+ properties->SetInteger(
+ "activeFrameColor",
+ native_app_window_->ActiveFrameColor() & transparent_white);
+ properties->SetInteger(
+ "inactiveFrameColor",
+ native_app_window_->InactiveFrameColor() & transparent_white);
gfx::Rect content_bounds = GetClientBounds();
gfx::Size content_min_size = native_app_window_->GetContentMinimumSize();
// Avoid using any previous app icons were being downloaded.
image_loader_ptr_factory_.InvalidateWeakPtrs();
+ const gfx::ImageSkia& default_icon =
+ *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
+ IDR_APP_DEFAULT_ICON);
+
+ const extensions::Extension* extension = GetExtension();
+ if (!extension)
+ return;
+
app_icon_image_.reset(
new extensions::IconImage(browser_context(),
- extension(),
- extensions::IconsInfo::GetIcons(extension()),
+ extension,
+ extensions::IconsInfo::GetIcons(extension),
delegate_->PreferredIconSize(),
- extensions::IconsInfo::GetDefaultAppIcon(),
+ default_icon,
this));
// Triggers actual image loading with 1x resources. The 2x resource will
}
#endif
+ const extensions::Extension* extension = GetExtension();
+ if (!extension)
+ return;
+
if (!IsExtensionWithPermissionOrSuggestInConsole(
- APIPermission::kFullscreen,
- extension_,
- source->GetRenderViewHost())) {
+ APIPermission::kFullscreen, extension, source->GetRenderViewHost())) {
return;
}
const extensions::Extension* unloaded_extension =
content::Details<extensions::UnloadedExtensionInfo>(details)
->extension;
- if (extension_ == unloaded_extension)
+ if (extension_id_ == unloaded_extension->id())
native_app_window_->Close();
break;
}
content::Details<const extensions::InstalledExtensionInfo>(details)
->extension;
DCHECK(installed_extension);
- if (installed_extension->id() == extension_->id())
+ if (installed_extension->id() == extension_id())
native_app_window_->UpdateShelfMenu();
break;
}
gfx::Screen::GetNativeScreen()->GetDisplayMatching(bounds).work_area();
ui::WindowShowState window_state = native_app_window_->GetRestoredState();
cache->SaveGeometry(
- extension()->id(), window_key_, bounds, screen_bounds, window_state);
+ extension_id(), window_key_, bounds, screen_bounds, window_state);
}
void AppWindow::AdjustBoundsToBeVisibleOnScreen(
gfx::Rect cached_bounds;
gfx::Rect cached_screen_bounds;
ui::WindowShowState cached_state = ui::SHOW_STATE_DEFAULT;
- if (cache->GetGeometry(extension()->id(),
+ if (cache->GetGeometry(extension_id(),
params.window_key,
&cached_bounds,
&cached_screen_bounds,
&cached_state)) {
-
// App window has cached screen bounds, make sure it fits on screen in
// case the screen resolution changed.
gfx::Screen* screen = gfx::Screen::GetNativeScreen();