Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add a loading property to WKBrowsingContextController
https://bugs.webkit.org/show_bug.cgi?id=125256

Reviewed by Dan Bernstein.

Source/WebKit2:

* UIProcess/API/Cocoa/WKBrowsingContextController.h:
Add loading property.

* UIProcess/API/Cocoa/WKBrowsingContextConteroller.mm:
Implement willChangeIsLoading and didChangeIsLoading and call the relevant KVO methods.

(-[WKBrowsingContextController isLoading]):
Call through to the PageLoadState.

* UIProcess/PageLoadState.cpp:
(WebKit::PageLoadState::reset):
Use setState.

(WebKit::PageLoadState::isLoading):
Call isLoadingState.

(WebKit::PageLoadState::didStartProvisionalLoad):
Use setState.

(WebKit::PageLoadState::didFailProvisionalLoad):
Use setState.

(WebKit::PageLoadState::didCommitLoad):
Use setState.

(WebKit::PageLoadState::didFinishLoad):
Use setState.

(WebKit::PageLoadState::didFailLoad):
Use setState.

(WebKit::PageLoadState::isLoadingState):
Helper function for determining whether a state is a loading state or not.

(WebKit::PageLoadState::setState):
If setting the state will cause "isLoading" to change, call out to the observers.

* UIProcess/PageLoadState.h:

Tools:

Bind the progress indicator visibility to the "loading" property.

* MiniBrowser/mac/WK2BrowserWindowController.m:
(-[WK2BrowserWindowController dealloc]):
(-[WK2BrowserWindowController awakeFromNib]):
(-[WK2BrowserWindowController didStartProgress]):
(-[WK2BrowserWindowController didFinishProgress]):

Canonical link: https://commits.webkit.org/143355@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@160129 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Anders Carlsson committed Dec 4, 2013
1 parent d1bdaec commit 5c6c149
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 9 deletions.
46 changes: 46 additions & 0 deletions Source/WebKit2/ChangeLog
@@ -1,3 +1,49 @@
2013-12-04 Anders Carlsson <andersca@apple.com>

Add a loading property to WKBrowsingContextController
https://bugs.webkit.org/show_bug.cgi?id=125256

Reviewed by Dan Bernstein.

* UIProcess/API/Cocoa/WKBrowsingContextController.h:
Add loading property.

* UIProcess/API/Cocoa/WKBrowsingContextConteroller.mm:
Implement willChangeIsLoading and didChangeIsLoading and call the relevant KVO methods.

(-[WKBrowsingContextController isLoading]):
Call through to the PageLoadState.

* UIProcess/PageLoadState.cpp:
(WebKit::PageLoadState::reset):
Use setState.

(WebKit::PageLoadState::isLoading):
Call isLoadingState.

(WebKit::PageLoadState::didStartProvisionalLoad):
Use setState.

(WebKit::PageLoadState::didFailProvisionalLoad):
Use setState.

(WebKit::PageLoadState::didCommitLoad):
Use setState.

(WebKit::PageLoadState::didFinishLoad):
Use setState.

(WebKit::PageLoadState::didFailLoad):
Use setState.

(WebKit::PageLoadState::isLoadingState):
Helper function for determining whether a state is a loading state or not.

(WebKit::PageLoadState::setState):
If setting the state will cause "isLoading" to change, call out to the observers.

* UIProcess/PageLoadState.h:

2013-12-04 Nick Diego Yamane <nick.yamane@openbossa.org>

[EFL][GTK][WK2] Remove unnecessary reinterpret_casts when setting API clients
Expand Down
Expand Up @@ -106,6 +106,8 @@ WK_API_CLASS

#pragma mark Active Load Introspection

@property (readonly, getter=isLoading) BOOL loading;

/* URL for the active load. This is the URL that should be shown in user interface. */
@property(readonly) NSURL *activeURL;

Expand Down
15 changes: 15 additions & 0 deletions Source/WebKit2/UIProcess/API/Cocoa/WKBrowsingContextController.mm
Expand Up @@ -61,6 +61,16 @@
}

private:
virtual void willChangeIsLoading() OVERRIDE
{
[m_controller willChangeValueForKey:@"loading"];
}

virtual void didChangeIsLoading() OVERRIDE
{
[m_controller didChangeValueForKey:@"loading"];
}

virtual void willChangeTitle() OVERRIDE
{
[m_controller willChangeValueForKey:@"title"];
Expand Down Expand Up @@ -269,6 +279,11 @@ - (WKBackForwardList *)backForwardList

#pragma mark Active Load Introspection

- (BOOL)isLoading
{
return _page->pageLoadState().isLoading();
}

- (NSURL *)activeURL
{
return [NSURL _web_URLWithWTFString:_page->pageLoadState().activeURL()];
Expand Down
55 changes: 49 additions & 6 deletions Source/WebKit2/UIProcess/PageLoadState.cpp
Expand Up @@ -55,7 +55,8 @@ void PageLoadState::removeObserver(Observer& observer)

void PageLoadState::reset()
{
m_state = State::Finished;
setState(State::Finished);

m_pendingAPIRequestURL = String();
m_provisionalURL = String();
m_url = String();
Expand All @@ -68,6 +69,11 @@ void PageLoadState::reset()
callObserverCallback(&Observer::didChangeTitle);
}

bool PageLoadState::isLoading() const
{
return isLoadingState(m_state);
}

String PageLoadState::activeURL() const
{
// If there is a currently pending URL, it is the active URL,
Expand Down Expand Up @@ -111,7 +117,8 @@ void PageLoadState::didStartProvisionalLoad(const String& url, const String& unr
{
ASSERT(m_provisionalURL.isEmpty());

m_state = State::Provisional;
setState(State::Provisional);

m_provisionalURL = url;

setUnreachableURL(unreachableURL);
Expand All @@ -128,7 +135,8 @@ void PageLoadState::didFailProvisionalLoad()
{
ASSERT(m_state == State::Provisional);

m_state = State::Finished;
setState(State::Finished);

m_provisionalURL = String();
m_unreachableURL = m_lastUnreachableURL;
}
Expand All @@ -137,7 +145,8 @@ void PageLoadState::didCommitLoad()
{
ASSERT(m_state == State::Provisional);

m_state = State::Committed;
setState(State::Committed);

m_url = m_provisionalURL;
m_provisionalURL = String();

Expand All @@ -149,14 +158,14 @@ void PageLoadState::didFinishLoad()
ASSERT(m_state == State::Committed);
ASSERT(m_provisionalURL.isEmpty());

m_state = State::Finished;
setState(State::Finished);
}

void PageLoadState::didFailLoad()
{
ASSERT(m_provisionalURL.isEmpty());

m_state = State::Finished;
setState(State::Finished);
}

void PageLoadState::didSameDocumentNavigation(const String& url)
Expand Down Expand Up @@ -184,6 +193,40 @@ void PageLoadState::setTitle(const String& title)
callObserverCallback(&Observer::didChangeTitle);
}

bool PageLoadState::isLoadingState(State state)
{
switch (state) {
case State::Provisional:
case State::Committed:
return true;

case State::Finished:
return false;
}

ASSERT_NOT_REACHED();
return false;
}

void PageLoadState::setState(State state)
{
if (m_state == state)
return;

bool isLoadingIsChanging = false;

if (isLoadingState(m_state) != isLoadingState(state))
isLoadingIsChanging = true;

if (isLoadingIsChanging)
callObserverCallback(&Observer::willChangeIsLoading);

m_state = state;

if (isLoadingIsChanging)
callObserverCallback(&Observer::didChangeIsLoading);
}

void PageLoadState::callObserverCallback(void (Observer::*callback)())
{
for (auto* observer : m_observers)
Expand Down
8 changes: 8 additions & 0 deletions Source/WebKit2/UIProcess/PageLoadState.h
Expand Up @@ -45,6 +45,9 @@ class PageLoadState {
public:
virtual ~Observer() { }

virtual void willChangeIsLoading() = 0;
virtual void didChangeIsLoading() = 0;

virtual void willChangeTitle() = 0;
virtual void didChangeTitle() = 0;
};
Expand All @@ -54,6 +57,8 @@ class PageLoadState {

void reset();

bool isLoading() const;

const String& provisionalURL() const { return m_provisionalURL; }
const String& url() const { return m_url; }
const String& unreachableURL() const { return m_unreachableURL; }
Expand All @@ -80,6 +85,9 @@ class PageLoadState {
void setTitle(const String&);

private:
static bool isLoadingState(State);
void setState(State);

void callObserverCallback(void (Observer::*)());

Vector<Observer*> m_observers;
Expand Down
15 changes: 15 additions & 0 deletions Tools/ChangeLog
@@ -1,3 +1,18 @@
2013-12-04 Anders Carlsson <andersca@apple.com>

Add a loading property to WKBrowsingContextController
https://bugs.webkit.org/show_bug.cgi?id=125256

Reviewed by Dan Bernstein.

Bind the progress indicator visibility to the "loading" property.

* MiniBrowser/mac/WK2BrowserWindowController.m:
(-[WK2BrowserWindowController dealloc]):
(-[WK2BrowserWindowController awakeFromNib]):
(-[WK2BrowserWindowController didStartProgress]):
(-[WK2BrowserWindowController didFinishProgress]):

2013-12-04 Nick Diego Yamane <nick.yamane@openbossa.org>

[EFL][WK2] Buildfix after r160104
Expand Down
8 changes: 5 additions & 3 deletions Tools/MiniBrowser/mac/WK2BrowserWindowController.m
Expand Up @@ -67,6 +67,8 @@ - (id)initWithContext:(WKContextRef)context pageGroup:(WKPageGroupRef)pageGroup

- (void)dealloc
{
[progressIndicator unbind:NSHiddenBinding];

WKRelease(_context);
WKRelease(_pageGroup);
_webView.browsingContextController.policyDelegate = nil;
Expand Down Expand Up @@ -614,7 +616,9 @@ - (void)awakeFromNib

[_webView setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)];
[containerView addSubview:_webView];


[progressIndicator bind:NSHiddenBinding toObject:_webView.browsingContextController withKeyPath:@"loading" options:@{ NSValueTransformerNameBindingOption : NSNegateBooleanTransformerName }];

WKPageLoaderClientV3 loadClient = {
{ 3, self },
didStartProvisionalLoadForFrame,
Expand Down Expand Up @@ -713,7 +717,6 @@ - (void)awakeFromNib
- (void)didStartProgress
{
[progressIndicator setDoubleValue:0.0];
[progressIndicator setHidden:NO];
}

- (void)didChangeProgress:(double)value
Expand All @@ -723,7 +726,6 @@ - (void)didChangeProgress:(double)value

- (void)didFinishProgress
{
[progressIndicator setHidden:YES];
[progressIndicator setDoubleValue:1.0];
}

Expand Down

0 comments on commit 5c6c149

Please sign in to comment.