diff options
Diffstat (limited to 'indra/newview/llfacebookconnect.cpp')
-rwxr-xr-x[-rw-r--r--] | indra/newview/llfacebookconnect.cpp | 305 |
1 files changed, 193 insertions, 112 deletions
diff --git a/indra/newview/llfacebookconnect.cpp b/indra/newview/llfacebookconnect.cpp index 514aac46fc..28319564e4 100644..100755 --- a/indra/newview/llfacebookconnect.cpp +++ b/indra/newview/llfacebookconnect.cpp @@ -28,6 +28,8 @@ #include "llviewerprecompiledheaders.h" #include "llfacebookconnect.h" +#include "llflickrconnect.h" +#include "lltwitterconnect.h" #include "llagent.h" #include "llcallingcard.h" // for LLAvatarTracker @@ -58,7 +60,7 @@ void log_facebook_connect_error(const std::string& request, U32 status, const st } } -void toast_user_for_success() +void toast_user_for_facebook_success() { LLSD args; args["MESSAGE"] = LLTrans::getString("facebook_post_success"); @@ -74,23 +76,46 @@ public: bool handle(const LLSD& tokens, const LLSD& query_map, LLMediaCtrl* web) { - if (tokens.size() > 0) + if (tokens.size() >= 1) { if (tokens[0].asString() == "connect") { - // this command probably came from the fbc_web browser, so close it - LLFloater* fbc_web = LLFloaterReg::getInstance("fbc_web"); - if (fbc_web) + if (tokens.size() >= 2 && tokens[1].asString() == "flickr") { - fbc_web->closeFloater(); + // this command probably came from the flickr_web browser, so close it + LLFloaterReg::hideInstance("flickr_web"); + + // connect to flickr + if (query_map.has("oauth_token")) + { + LLFlickrConnect::instance().connectToFlickr(query_map["oauth_token"], query_map.get("oauth_verifier")); + } + return true; } - - // connect to facebook - if (query_map.has("code")) + else if (tokens.size() >= 2 && tokens[1].asString() == "twitter") + { + // this command probably came from the twitter_web browser, so close it + LLFloaterReg::hideInstance("twitter_web"); + + // connect to twitter + if (query_map.has("oauth_token")) + { + LLTwitterConnect::instance().connectToTwitter(query_map["oauth_token"], query_map.get("oauth_verifier")); + } + return true; + } + else //if (tokens.size() >= 2 && tokens[1].asString() == "facebook") { - LLFacebookConnect::instance().connectToFacebook(query_map["code"], query_map.get("state")); + // this command probably came from the fbc_web browser, so close it + LLFloaterReg::hideInstance("fbc_web"); + + // connect to facebook + if (query_map.has("code")) + { + LLFacebookConnect::instance().connectToFacebook(query_map["code"], query_map.get("state")); + } + return true; } - return true; } } return false; @@ -110,28 +135,36 @@ public: LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_CONNECTION_IN_PROGRESS); } - virtual void completed(U32 status, const std::string& reason, const LLSD& content) + /* virtual */ void httpSuccess() + { + LL_DEBUGS("FacebookConnect") << "Connect successful. " << dumpResponse() << LL_ENDL; + LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_CONNECTED); + } + + /* virtual */ void httpFailure() { - if (isGoodStatus(status)) + if ( HTTP_FOUND == getStatus() ) { - LL_DEBUGS("FacebookConnect") << "Connect successful. content: " << content << LL_ENDL; - - LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_CONNECTED); + const std::string& location = getResponseHeader(HTTP_IN_HEADER_LOCATION); + if (location.empty()) + { + LL_WARNS("FacebookConnect") << "Missing Location header " << dumpResponse() + << "[headers:" << getResponseHeaders() << "]" << LL_ENDL; + } + else + { + LLFacebookConnect::instance().openFacebookWeb(location); + } } - else if (status != 302) + else { - LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_CONNECTION_FAILED); - log_facebook_connect_error("Connect", status, reason, content.get("error_code"), content.get("error_description")); + LL_WARNS("FacebookConnect") << dumpResponse() << LL_ENDL; + LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_CONNECTION_FAILED); + const LLSD& content = getContent(); + log_facebook_connect_error("Connect", getStatus(), getReason(), + content.get("error_code"), content.get("error_description")); } } - - void completedHeader(U32 status, const std::string& reason, const LLSD& content) - { - if (status == 302) - { - LLFacebookConnect::instance().openFacebookWeb(content["location"]); - } - } }; /////////////////////////////////////////////////////////////////////////////// @@ -145,34 +178,42 @@ public: { LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_POSTING); } - - virtual void completed(U32 status, const std::string& reason, const LLSD& content) + + /* virtual */ void httpSuccess() { - if (isGoodStatus(status)) + toast_user_for_facebook_success(); + LL_DEBUGS("FacebookConnect") << "Post successful. " << dumpResponse() << LL_ENDL; + LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_POSTED); + } + + /* virtual */ void httpFailure() + { + if ( HTTP_FOUND == getStatus() ) { - toast_user_for_success(); - LL_DEBUGS("FacebookConnect") << "Post successful. content: " << content << LL_ENDL; - - LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_POSTED); + const std::string& location = getResponseHeader(HTTP_IN_HEADER_LOCATION); + if (location.empty()) + { + LL_WARNS("FacebookConnect") << "Missing Location header " << dumpResponse() + << "[headers:" << getResponseHeaders() << "]" << LL_ENDL; + } + else + { + LLFacebookConnect::instance().openFacebookWeb(location); + } } - else if (status == 404) + else if ( HTTP_NOT_FOUND == getStatus() ) { LLFacebookConnect::instance().connectToFacebook(); } else { - LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_POST_FAILED); - log_facebook_connect_error("Share", status, reason, content.get("error_code"), content.get("error_description")); + LL_WARNS("FacebookConnect") << dumpResponse() << LL_ENDL; + LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_POST_FAILED); + const LLSD& content = getContent(); + log_facebook_connect_error("Share", getStatus(), getReason(), + content.get("error_code"), content.get("error_description")); } } - - void completedHeader(U32 status, const std::string& reason, const LLSD& content) - { - if (status == 302) - { - LLFacebookConnect::instance().openFacebookWeb(content["location"]); - } - } }; /////////////////////////////////////////////////////////////////////////////// @@ -196,24 +237,27 @@ public: LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_NOT_CONNECTED); } - virtual void completed(U32 status, const std::string& reason, const LLSD& content) + /* virtual */ void httpSuccess() { - if (isGoodStatus(status)) - { - LL_DEBUGS("FacebookConnect") << "Disconnect successful. content: " << content << LL_ENDL; - setUserDisconnected(); + LL_DEBUGS("FacebookConnect") << "Disconnect successful. " << dumpResponse() << LL_ENDL; + setUserDisconnected(); + } - } + /* virtual */ void httpFailure() + { //User not found so already disconnected - else if(status == 404) + if ( HTTP_NOT_FOUND == getStatus() ) { - LL_DEBUGS("FacebookConnect") << "Already disconnected. content: " << content << LL_ENDL; + LL_DEBUGS("FacebookConnect") << "Already disconnected. " << dumpResponse() << LL_ENDL; setUserDisconnected(); } else { + LL_WARNS("FacebookConnect") << dumpResponse() << LL_ENDL; LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_DISCONNECT_FAILED); - log_facebook_connect_error("Disconnect", status, reason, content.get("error_code"), content.get("error_description")); + const LLSD& content = getContent(); + log_facebook_connect_error("Disconnect", getStatus(), getReason(), + content.get("error_code"), content.get("error_description")); } } }; @@ -229,34 +273,35 @@ public: { LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_CONNECTION_IN_PROGRESS); } - - virtual void completed(U32 status, const std::string& reason, const LLSD& content) + + /* virtual */ void httpSuccess() + { + LL_DEBUGS("FacebookConnect") << "Connect successful. " << dumpResponse() << LL_ENDL; + LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_CONNECTED); + } + + /* virtual */ void httpFailure() { - if (isGoodStatus(status)) + // show the facebook login page if not connected yet + if ( HTTP_NOT_FOUND == getStatus() ) { - LL_DEBUGS("FacebookConnect") << "Connect successful. content: " << content << LL_ENDL; - - LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_CONNECTED); + LL_DEBUGS("FacebookConnect") << "Not connected. " << dumpResponse() << LL_ENDL; + if (mAutoConnect) + { + LLFacebookConnect::instance().connectToFacebook(); + } + else + { + LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_NOT_CONNECTED); + } } else { - // show the facebook login page if not connected yet - if (status == 404) - { - if (mAutoConnect) - { - LLFacebookConnect::instance().connectToFacebook(); - } - else - { - LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_NOT_CONNECTED); - } - } - else - { - LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_CONNECTION_FAILED); - log_facebook_connect_error("Connected", status, reason, content.get("error_code"), content.get("error_description")); - } + LL_WARNS("FacebookConnect") << dumpResponse() << LL_ENDL; + LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_DISCONNECT_FAILED); + const LLSD& content = getContent(); + log_facebook_connect_error("Connected", getStatus(), getReason(), + content.get("error_code"), content.get("error_description")); } } @@ -271,25 +316,34 @@ class LLFacebookInfoResponder : public LLHTTPClient::Responder LOG_CLASS(LLFacebookInfoResponder); public: - virtual void completed(U32 status, const std::string& reason, const LLSD& info) + /* virtual */ void httpSuccess() { - if (isGoodStatus(status)) - { - LL_INFOS() << "Facebook: Info received" << LL_ENDL; - LL_DEBUGS("FacebookConnect") << "Getting Facebook info successful. info: " << info << LL_ENDL; - LLFacebookConnect::instance().storeInfo(info); - } - else - { - log_facebook_connect_error("Info", status, reason, info.get("error_code"), info.get("error_description")); - } + LL_INFOS("FacebookConnect") << "Facebook: Info received" << LL_ENDL; + LL_DEBUGS("FacebookConnect") << "Getting Facebook info successful. " << dumpResponse() << LL_ENDL; + LLFacebookConnect::instance().storeInfo(getContent()); } - void completedHeader(U32 status, const std::string& reason, const LLSD& content) + /* virtual */ void httpFailure() { - if (status == 302) + if ( HTTP_FOUND == getStatus() ) { - LLFacebookConnect::instance().openFacebookWeb(content["location"]); + const std::string& location = getResponseHeader(HTTP_IN_HEADER_LOCATION); + if (location.empty()) + { + LL_WARNS("FacebookConnect") << "Missing Location header " << dumpResponse() + << "[headers:" << getResponseHeaders() << "]" << LL_ENDL; + } + else + { + LLFacebookConnect::instance().openFacebookWeb(location); + } + } + else + { + LL_WARNS("FacebookConnect") << dumpResponse() << LL_ENDL; + const LLSD& content = getContent(); + log_facebook_connect_error("Info", getStatus(), getReason(), + content.get("error_code"), content.get("error_description")); } } }; @@ -300,27 +354,36 @@ class LLFacebookFriendsResponder : public LLHTTPClient::Responder { LOG_CLASS(LLFacebookFriendsResponder); public: + + /* virtual */ void httpSuccess() + { + LL_DEBUGS("FacebookConnect") << "Getting Facebook friends successful. " << dumpResponse() << LL_ENDL; + LLFacebookConnect::instance().storeContent(getContent()); + } - virtual void completed(U32 status, const std::string& reason, const LLSD& content) + /* virtual */ void httpFailure() { - if (isGoodStatus(status)) + if ( HTTP_FOUND == getStatus() ) { - LL_DEBUGS("FacebookConnect") << "Getting Facebook friends successful. content: " << content << LL_ENDL; - LLFacebookConnect::instance().storeContent(content); + const std::string& location = getResponseHeader(HTTP_IN_HEADER_LOCATION); + if (location.empty()) + { + LL_WARNS("FacebookConnect") << "Missing Location header " << dumpResponse() + << "[headers:" << getResponseHeaders() << "]" << LL_ENDL; + } + else + { + LLFacebookConnect::instance().openFacebookWeb(location); + } } else { - log_facebook_connect_error("Friends", status, reason, content.get("error_code"), content.get("error_description")); + LL_WARNS("FacebookConnect") << dumpResponse() << LL_ENDL; + const LLSD& content = getContent(); + log_facebook_connect_error("Friends", getStatus(), getReason(), + content.get("error_code"), content.get("error_description")); } } - - void completedHeader(U32 status, const std::string& reason, const LLSD& content) - { - if (status == 302) - { - LLFacebookConnect::instance().openFacebookWeb(content["location"]); - } - } }; /////////////////////////////////////////////////////////////////////////////// @@ -340,10 +403,12 @@ void LLFacebookConnect::openFacebookWeb(std::string url) { // Open the URL in an internal browser window without navigation UI LLFloaterWebContent::Params p; - p.url(url).show_chrome(true); - p.url(url).allow_address_entry(false); - p.url(url).allow_back_forward_navigation(false); - p.url(url).trusted_content(true); + p.url(url); + p.show_chrome(true); + p.allow_address_entry(false); + p.allow_back_forward_navigation(false); + p.trusted_content(true); + p.clean_browser(true); LLFloater *floater = LLFloaterReg::showInstance("fbc_web", p); //the internal web browser has a bug that prevents it from gaining focus unless a mouse event occurs first (it seems). //So when showing the internal web browser, set focus to it's containing floater "fbc_web". When a mouse event @@ -360,7 +425,8 @@ std::string LLFacebookConnect::getFacebookConnectURL(const std::string& route, b LLViewerRegion *regionp = gAgent.getRegion(); if (regionp) { - url = regionp->getCapability("FacebookConnect"); + //url = "http://pdp15.lindenlab.com/fbc/agent/" + gAgentID.asString(); // TEMPORARY FOR TESTING - CHO + url = regionp->getCapability("FacebookConnect"); url += route; if (include_read_from_master && mReadFromMaster) @@ -375,9 +441,13 @@ void LLFacebookConnect::connectToFacebook(const std::string& auth_code, const st { LLSD body; if (!auth_code.empty()) + { body["code"] = auth_code; + } if (!auth_state.empty()) + { body["state"] = auth_state; + } LLHTTPClient::put(getFacebookConnectURL("/connection"), body, new LLFacebookConnectResponder()); } @@ -421,15 +491,25 @@ void LLFacebookConnect::postCheckin(const std::string& location, const std::stri { LLSD body; if (!location.empty()) + { body["location"] = location; + } if (!name.empty()) + { body["name"] = name; + } if (!description.empty()) + { body["description"] = description; + } if (!image.empty()) + { body["image"] = image; + } if (!message.empty()) + { body["message"] = message; + } // Note: we can use that route for different publish action. We should be able to use the same responder. LLHTTPClient::post(getFacebookConnectURL("/share/checkin", true), body, new LLFacebookShareResponder()); @@ -476,7 +556,7 @@ void LLFacebookConnect::sharePhoto(LLPointer<LLImageFormatted> image, const std: << caption << "\r\n"; body << "--" << boundary << "\r\n" - << "Content-Disposition: form-data; name=\"image\"; filename=\"snapshot." << imageFormat << "\"\r\n" + << "Content-Disposition: form-data; name=\"image\"; filename=\"Untitled." << imageFormat << "\"\r\n" << "Content-Type: image/" << imageFormat << "\r\n\r\n"; // Insert the image data. @@ -568,12 +648,13 @@ void LLFacebookConnect::setConnectionState(LLFacebookConnect::EConnectionState c if (mConnectionState != connection_state) { + // set the connection state before notifying watchers + mConnectionState = connection_state; + LLSD state_info; state_info["enum"] = connection_state; sStateWatcher->post(state_info); } - - mConnectionState = connection_state; } void LLFacebookConnect::setConnected(bool connected) |