#include "atom/common/api/api_messages.h"
#include "atom/common/native_mate_converters/gfx_converter.h"
#include "atom/common/native_mate_converters/gurl_converter.h"
+#include "atom/common/native_mate_converters/image_converter.h"
#include "atom/common/native_mate_converters/string16_converter.h"
#include "atom/common/native_mate_converters/value_converter.h"
#include "base/strings/utf_string_conversions.h"
#include "brightray/browser/inspectable_web_contents.h"
+#include "content/public/browser/favicon_status.h"
#include "content/public/browser/navigation_details.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/render_frame_host.h"
if (url.is_valid())
unique_urls.insert(url);
}
- Emit("page-favicon-set", unique_urls);
+ Emit("page-favicon-updated", unique_urls);
}
bool WebContents::OnMessageReceived(const IPC::Message& message) {
void WebContents::NavigationEntryCommitted(
const content::LoadCommittedDetails& load_details) {
+ if (load_details.is_navigation_to_different_page())
+ Emit("did-navigate");
auto entry = web_contents()->GetController().GetLastCommittedEntry();
entry->SetVirtualURL(load_details.entry->GetOriginalRequestURL());
}
return web_contents()->GetTitle();
}
+gfx::Image WebContents::GetFavicon() const {
+ auto entry = web_contents()->GetController().GetLastCommittedEntry();
+ if (!entry)
+ return gfx::Image();
+ auto favicon_status = entry->GetFavicon();
+ return favicon_status.image;
+}
+
bool WebContents::IsLoading() const {
return web_contents()->IsLoading();
}
.SetMethod("_loadUrl", &WebContents::LoadURL)
.SetMethod("getUrl", &WebContents::GetURL)
.SetMethod("getTitle", &WebContents::GetTitle)
+ .SetMethod("getFavicon", &WebContents::GetFavicon)
.SetMethod("isLoading", &WebContents::IsLoading)
.SetMethod("isWaitingForResponse", &WebContents::IsWaitingForResponse)
.SetMethod("stop", &WebContents::Stop)
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_observer.h"
#include "native_mate/handle.h"
+#include "ui/gfx/image/image.h"
namespace brightray {
class InspectableWebContents;
void LoadURL(const GURL& url, const mate::Dictionary& options);
GURL GetURL() const;
base::string16 GetTitle() const;
+ gfx::Image GetFavicon() const;
bool IsLoading() const;
bool IsWaitingForResponse() const;
void Stop();
'did-finish-load'
'did-fail-load'
'did-frame-finish-load'
+ 'did-navigate'
'did-start-loading'
'did-stop-loading'
'did-get-response-details'
'crashed'
'destroyed'
'page-title-set'
- 'page-favicon-set'
+ 'page-favicon-updated'
]
nextInstanceId = 0
'did-finish-load': []
'did-fail-load': ['errorCode', 'errorDescription']
'did-frame-finish-load': ['isMainFrame']
+ 'did-navigate': []
'did-start-loading': []
'did-stop-loading': []
'did-get-response-details': ['status', 'newUrl', 'originalUrl',
'crashed': []
'destroyed': []
'page-title-set': ['title', 'explicitSet']
- 'page-favicon-set': ['favicons']
+ 'page-favicon-updated': ['favicons']
dispatchEvent = (webView, event, args...) ->
throw new Error("Unkown event #{event}") unless WEB_VIEW_EVENTS[event]?
not @.getValue()
return
+ # Allow users to cancel webview navigation.
domEvent = new Event('will-navigate')
domEvent['url'] = @getValue()
domEvent.cancelable = true
methods = [
"getUrl"
"getTitle"
+ "getFavicon"
"isLoading"
"isWaitingForResponse"
"stop"
Emitted when a frame has done navigation.
+### Event: 'did-navigate'
+
+* `event` Event
+
+Emitted when a frame navigation has been committed to history.
+
### Event: 'did-start-loading'
Corresponds to the points in time when the spinner of the tab starts spinning.
Emitted when a redirect was received while requesting a resource.
-### Event: 'page-favicon-set'
+### Event: 'page-favicon-updated'
* `event` Event
* `favicons` [String]
Returns the title of web page.
+### WebContents.getFavicon()
+
+Returns the favicon of web page as `nativeImage`.
+
### WebContents.isLoading()
Returns whether web page is still loading resources.
Returns the title of guest page.
+### `<webview>`.getFavicon()
+
+Returns the favicon of guest page as `nativeImage`.
+
### `<webview>`.isLoading()
Returns whether guest page is still loading resources.
Fired when a frame has done navigation.
+### did-navigate
+
+Fired when a frame navigation has been committed to history.
+
### did-start-loading
Corresponds to the points in time when the spinner of the tab starts spinning.
Fired when page title is set during navigation. `explicitSet` is false when title is synthesised from file
url.
-### page-favicon-set
+### page-favicon-updated
* `favicons` [String]
describe 'will-navigate event', ->
it 'is emitted before navigation', (done) ->
- webview.addEventListener 'will-navigate', (e) ->
+ view = new WebView
+ view.addEventListener 'will-navigate', (e) ->
e.preventDefault()
assert.equal webview.src, ''
+ view.addEventListener 'did-navigate', (e) ->
+ document.body.removeChild view
done()
- webview.src = "file://#{fixtures}/pages/a.html"
+ view.src = "file://#{fixtures}/pages/a.html"
+ document.body.appendChild view
document.body.appendChild webview
- describe 'page-favicon-set event', ->
- it 'emits when favicon is set', (done) ->
- webview.addEventListener 'page-favicon-set', (e) ->
+ describe 'page-favicon-updated event', ->
+ it 'emits when favicon urls are received', (done) ->
+ webview.addEventListener 'page-favicon-updated', (e) ->
assert.equal e.favicons.length, 2
assert.equal e.favicons[0], 'file:///favicon.png'
done()