diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 9b7cb204df3b..40498153c3fe 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -366,6 +366,10 @@ void Window::Print(mate::Arguments* args) { window_->Print(settings.silent, settings.print_backgournd); } +void Window::SetProgressBar(double progress) { + window_->SetProgressBar(progress); +} + mate::Handle Window::GetWebContents(v8::Isolate* isolate) const { return WebContents::Create(isolate, window_->GetWebContents()); } @@ -428,6 +432,7 @@ void Window::BuildPrototype(v8::Isolate* isolate, .SetMethod("isWebViewFocused", &Window::IsWebViewFocused) .SetMethod("capturePage", &Window::CapturePage) .SetMethod("print", &Window::Print) + .SetMethod("setProgressBar", &Window::SetProgressBar) .SetMethod("_getWebContents", &Window::GetWebContents) .SetMethod("_getDevToolsWebContents", &Window::GetDevToolsWebContents); } diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index e558b5ce00d3..25ea3700cf81 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -103,6 +103,7 @@ class Window : public mate::EventEmitter, bool IsDocumentEdited(); void CapturePage(mate::Arguments* args); void Print(mate::Arguments* args); + void SetProgressBar(double progress); // APIs for WebContents. mate::Handle GetWebContents(v8::Isolate* isolate) const; diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 1da62ce3f7bd..929c1aabc5bb 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -140,6 +140,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, virtual void SetMenu(ui::MenuModel* menu); virtual bool HasModalDialog(); virtual gfx::NativeWindow GetNativeWindow() = 0; + virtual void SetProgressBar(double progress) = 0; virtual bool IsClosed() const { return is_closed_; } virtual void OpenDevTools(); diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 3892b7181b94..d3eec5c1c57f 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -43,7 +43,9 @@ #elif defined(OS_WIN) #include "atom/browser/ui/views/win_frame_view.h" #include "base/win/scoped_comptr.h" +#include "base/win/windows_version.h" #include "ui/base/win/shell.h" +#include "ui/views/win/hwnd_util.h" #endif namespace atom { @@ -479,6 +481,27 @@ gfx::NativeWindow NativeWindowViews::GetNativeWindow() { return window_->GetNativeWindow(); } +void NativeWindowViews::SetProgressBar(double progress) { +#if defined(OS_WIN) + if (base::win::GetVersion() < base::win::VERSION_WIN7) + return; + base::win::ScopedComPtr taskbar; + if (FAILED(taskbar.CreateInstance(CLSID_TaskbarList, NULL, + CLSCTX_INPROC_SERVER) || + FAILED(taskbar->HrInit()))) { + return; + } + HWND frame = views::HWNDForNativeWindow(GetNativeWindow()); + if (progress > 1.0) { + taskbar->SetProgressState(frame, TBPF_INDETERMINATE); + } else if (progress < 0) { + taskbar->SetProgressState(frame, TBPF_NOPROGRESS); + } else if (progress >= 0) { + taskbar->SetProgressValue(frame, static_cast(progress*100), progress); + } +#endif +} + gfx::AcceleratedWidget NativeWindowViews::GetAcceleratedWidget() { return GetNativeWindow()->GetHost()->GetAcceleratedWidget(); } diff --git a/atom/browser/native_window_views.h b/atom/browser/native_window_views.h index 3d81a68be224..b38769c39265 100644 --- a/atom/browser/native_window_views.h +++ b/atom/browser/native_window_views.h @@ -71,6 +71,7 @@ class NativeWindowViews : public NativeWindow, virtual bool IsKiosk() OVERRIDE; virtual void SetMenu(ui::MenuModel* menu_model) OVERRIDE; virtual gfx::NativeWindow GetNativeWindow() OVERRIDE; + virtual void SetProgressBar(double value) OVERRIDE; gfx::AcceleratedWidget GetAcceleratedWidget();