#include <string>
+#include "base/file_util.h"
#include "base/message_loop.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "ui/gfx/point.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"
+#include "webkit/glue/image_decoder.h"
using content::NavigationEntry;
brightray::InspectableWebContents::Create(web_contents)) {
options->GetBoolean(switches::kFrame, &has_frame_);
+ std::string icon;
+ if (options->GetString(switches::kIcon, &icon)) {
+ if (!SetIcon(icon))
+ LOG(ERROR) << "Failed to set icon to " << icon;
+ }
+
web_contents->SetDelegate(this);
WindowList::AddWindow(this);
GetWebContents()->GetRenderViewHost()->RestartHangMonitorTimeout();
}
+bool NativeWindow::SetIcon(const std::string& str_path) {
+ base::FilePath path = base::FilePath::FromUTF8Unsafe(str_path);
+
+ // Read the file from disk.
+ std::string file_contents;
+ if (path.empty() || !file_util::ReadFileToString(path, &file_contents))
+ return false;
+
+ // Decode the bitmap using WebKit's image decoder.
+ const unsigned char* data =
+ reinterpret_cast<const unsigned char*>(file_contents.data());
+ webkit_glue::ImageDecoder decoder;
+ scoped_ptr<SkBitmap> decoded(new SkBitmap());
+ *decoded = decoder.Decode(data, file_contents.length());
+ if (decoded->empty())
+ return false; // Unable to decode.
+
+ icon_ = gfx::Image::CreateFrom1xBitmap(*decoded.release());
+ return true;
+}
+
void NativeWindow::CloseWebContents() {
bool prevent_default = false;
FOR_EACH_OBSERVER(NativeWindowObserver,
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/web_contents_observer.h"
+#include "ui/gfx/image/image.h"
#include "vendor/brightray/browser/default_web_contents_delegate.h"
namespace base {
virtual void BlurWebView();
virtual bool IsWebViewFocused();
virtual void RestartHangMonitorTimeout();
+ virtual bool SetIcon(const std::string& path);
// The same with closing a tab in a real browser.
//
// Whether window has standard frame.
bool has_frame_;
+ // Window icon.
+ gfx::Image icon_;
+
private:
void RendererUnresponsiveDelayed();
#include "browser/native_window_win.h"
-#include "app/win/resource.h"
#include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
const int kResizeInsideBoundsSize = 5;
const int kResizeAreaCornerSize = 16;
-HANDLE g_exe_icon = NULL;
-
// Wrapper of NativeWidgetWin to handle WM_MENUCOMMAND messages, which are
// triggered by window menus.
class MenuCommandNativeWidget : public views::NativeWidgetWin {
gfx::Size size(width, height);
window_->CenterWindow(size);
+ window_->UpdateWindowIcon();
+
web_view_->SetWebContents(web_contents);
OnViewWasResized();
-
- if (g_exe_icon == NULL)
- g_exe_icon = ::LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(1),
- IMAGE_ICON, 0, 0, 0);
- ::SendMessage(window_->GetNativeWindow(),
- WM_SETICON,
- static_cast<WPARAM>(ICON_BIG),
- reinterpret_cast<LPARAM>(g_exe_icon));
}
NativeWindowWin::~NativeWindowWin() {
return true;
}
-bool NativeWindowWin::ShouldShowWindowIcon() const {
- return true;
+gfx::ImageSkia NativeWindowWin::GetWindowAppIcon() {
+ if (icon_.IsEmpty())
+ return gfx::ImageSkia();
+ else
+ return *icon_.ToImageSkia();
+}
+
+gfx::ImageSkia NativeWindowWin::GetWindowIcon() {
+ return GetWindowAppIcon();
}
views::Widget* NativeWindowWin::GetWidget() {
virtual bool CanMaximize() const OVERRIDE;
virtual string16 GetWindowTitle() const OVERRIDE;
virtual bool ShouldHandleSystemCommands() const OVERRIDE;
- virtual bool ShouldShowWindowIcon() const OVERRIDE;
+ virtual gfx::ImageSkia GetWindowAppIcon() OVERRIDE;
+ virtual gfx::ImageSkia GetWindowIcon() OVERRIDE;
virtual views::Widget* GetWidget() OVERRIDE;
virtual const views::Widget* GetWidget() const OVERRIDE;
virtual views::ClientView* CreateClientView(views::Widget* widget) OVERRIDE;